From c19ff75707621b0c5bcb832da84921a0370d72a8 Mon Sep 17 00:00:00 2001 From: Denis Dzyubenko Date: Fri, 20 May 2011 14:37:55 +0200 Subject: Improved performance of the QLocale::name() function. Task-number: QTBUG-19168 Reviewed-by: Zeno Albisser --- src/corelib/tools/qlocale.cpp | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/src/corelib/tools/qlocale.cpp b/src/corelib/tools/qlocale.cpp index c8ed94b..c398a5c 100644 --- a/src/corelib/tools/qlocale.cpp +++ b/src/corelib/tools/qlocale.cpp @@ -942,19 +942,32 @@ QLocale::Country QLocale::country() const QString QLocale::name() const { - Language l = language(); + const QLocalePrivate *dd = d(); - QString result = d()->languageCode(); + if (dd->m_language_id == QLocale::AnyLanguage) + return QString(); + if (dd->m_language_id == QLocale::C) + return QLatin1String("C"); - if (l == C) - return result; + const unsigned char *c = language_code_list + 3*(uint(dd->m_language_id)); - Country c = country(); - if (c == AnyCountry) - return result; + QString result(7, Qt::Uninitialized); + ushort *data = (ushort *)result.unicode(); + const ushort *begin = data; - result.append(QLatin1Char('_')); - result.append(d()->countryCode()); + *data++ = ushort(c[0]); + *data++ = ushort(c[1]); + if (c[2] != 0) + *data++ = ushort(c[2]); + if (dd->m_country_id != AnyCountry) { + *data++ = '_'; + const unsigned char *c = country_code_list + 3*(uint(dd->m_country_id)); + *data++ = ushort(c[0]); + *data++ = ushort(c[1]); + if (c[2] != 0) + *data++ = ushort(c[2]); + } + result.resize(data - begin); return result; } -- cgit v0.12