From 30a8d73fdca819f8803bbb12cdf51bba1d09b22f Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 25 Apr 2013 21:50:18 -0700 Subject: QLocale: cache the C locale's private Change-Id: I81bbfeffebb5b7fc29d67bb7127beaf13838ac9f Reviewed-by: Lars Knoll --- src/corelib/tools/qlocale.cpp | 15 ++++++++++++++- src/corelib/tools/qlocale_p.h | 1 + 2 files changed, 15 insertions(+), 1 deletion(-) (limited to 'src/corelib') diff --git a/src/corelib/tools/qlocale.cpp b/src/corelib/tools/qlocale.cpp index 3c918864f9..57f9b22e53 100644 --- a/src/corelib/tools/qlocale.cpp +++ b/src/corelib/tools/qlocale.cpp @@ -529,6 +529,9 @@ int qt_repeatCount(const QString &s, int i) static const QLocaleData *default_data = 0; static uint default_number_options = 0; +static const QLocaleData *const c_data = locale_data; +static QLocalePrivate c_private = { c_data, Q_BASIC_ATOMIC_INITIALIZER(1), 0 }; + #ifndef QT_NO_SYSTEMLOCALE @@ -643,6 +646,12 @@ static const QLocaleData *defaultData() return default_data; } +const QLocaleData *QLocaleData::c() +{ + Q_ASSERT(locale_index[QLocale::C] == 0); + return c_data; +} + static QString getLocaleListData(const ushort *data, int size, int index) { static const ushort separator = ';'; @@ -699,9 +708,10 @@ const QLocaleData *QLocalePrivate::dataPointerForIndex(quint16 index) return &locale_data[index]; } - static QLocalePrivate *localePrivateByName(const QString &name) { + if (name == QLatin1String("C")) + return &c_private; return QLocalePrivate::create(findLocaleData(name)); } @@ -713,6 +723,9 @@ static QLocalePrivate *defaultLocalePrivate() static QLocalePrivate *findLocalePrivate(QLocale::Language language, QLocale::Script script, QLocale::Country country) { + if (language == QLocale::C) + return &c_private; + const QLocaleData *data = QLocaleData::findLocaleData(language, script, country); int numberOptions = 0; diff --git a/src/corelib/tools/qlocale_p.h b/src/corelib/tools/qlocale_p.h index d3b0765f6c..a62ee9304b 100644 --- a/src/corelib/tools/qlocale_p.h +++ b/src/corelib/tools/qlocale_p.h @@ -164,6 +164,7 @@ public: static const QLocaleData *findLocaleData(QLocale::Language language, QLocale::Script script, QLocale::Country country); + static const QLocaleData *c(); quint16 m_language_id, m_script_id, m_country_id; -- cgit v1.2.3