From 59928d23fc22d916dea32f02d810b8b24b74922d Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 30 Jan 2017 15:25:23 +0100 Subject: 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 Reviewed-by: Thiago Macieira --- src/corelib/tools/qlocale_p.h | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'src/corelib/tools/qlocale_p.h') 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()); } -- cgit v1.2.3