summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2013-04-25 21:50:18 -0700
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-05-01 23:05:35 +0200
commit30a8d73fdca819f8803bbb12cdf51bba1d09b22f (patch)
tree345ca1e054d9db7c41a6f83d86c22d10f5f2921a
parenta2f59955ae2f6c421496b8001894418ff930e9b8 (diff)
QLocale: cache the C locale's private
Change-Id: I81bbfeffebb5b7fc29d67bb7127beaf13838ac9f Reviewed-by: Lars Knoll <lars.knoll@digia.com>
-rw-r--r--src/corelib/tools/qlocale.cpp15
-rw-r--r--src/corelib/tools/qlocale_p.h1
2 files changed, 15 insertions, 1 deletions
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;