diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2017-01-30 15:25:23 +0100 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2017-03-26 06:44:29 +0000 |
commit | 59928d23fc22d916dea32f02d810b8b24b74922d (patch) | |
tree | 5b1bc9c5e3cdb713e8cd716df8189bb3afd361c6 /src/corelib/tools/qlocale_p.h | |
parent | 610a9e8f319eafcbcf193e4b90119a6f89d0caf9 (diff) |
Port QLocalePrivate::*ToCode() to QLatin1String
The returned data is in US-ASCII (or else Latin-1), and resides in
consecutive memory. We can therefore return it in a QLatin1String,
which, however, will in general not be NUL-terminated.
Many users use the return value as part of a QStringBuilder
expression, and those which are not are not pessimized further by
this change.
The caller in qtimezoneprivate_icu looks as if it could simply zero
-terminate the return value and use it as-is, as opposed to
converting to UTF-8, but I left the code equivalent to the original
just the same.
Change-Id: I0e628af8c1320fcff8d0aacf160e859681d2b85a
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/tools/qlocale_p.h')
-rw-r--r-- | src/corelib/tools/qlocale_p.h | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/src/corelib/tools/qlocale_p.h b/src/corelib/tools/qlocale_p.h index f7adb021b6..1c6e3e850b 100644 --- a/src/corelib/tools/qlocale_p.h +++ b/src/corelib/tools/qlocale_p.h @@ -349,14 +349,13 @@ public: QByteArray bcp47Name(char separator = '-') const; - // ### QByteArray::fromRawData would be more optimal - inline QString languageCode() const { return QLocalePrivate::languageToCode(QLocale::Language(m_data->m_language_id)); } - inline QString scriptCode() const { return QLocalePrivate::scriptToCode(QLocale::Script(m_data->m_script_id)); } - inline QString countryCode() const { return QLocalePrivate::countryToCode(QLocale::Country(m_data->m_country_id)); } - - static QString languageToCode(QLocale::Language language); - static QString scriptToCode(QLocale::Script script); - static QString countryToCode(QLocale::Country country); + inline QLatin1String languageCode() const { return QLocalePrivate::languageToCode(QLocale::Language(m_data->m_language_id)); } + inline QLatin1String scriptCode() const { return QLocalePrivate::scriptToCode(QLocale::Script(m_data->m_script_id)); } + inline QLatin1String countryCode() const { return QLocalePrivate::countryToCode(QLocale::Country(m_data->m_country_id)); } + + static QLatin1String languageToCode(QLocale::Language language); + static QLatin1String scriptToCode(QLocale::Script script); + static QLatin1String countryToCode(QLocale::Country country); static QLocale::Language codeToLanguage(const QChar *code, int len) Q_DECL_NOTHROW; static QLocale::Language codeToLanguage(const QString &code) Q_DECL_NOTHROW { return codeToLanguage(code.data(), code.size()); } static QLocale::Language codeToLanguage(const QStringRef &code) Q_DECL_NOTHROW { return codeToLanguage(code.data(), code.size()); } |