From 5da8e5ddd424a11435a3750dc9b955295aeaed9c Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 25 Apr 2013 22:28:13 -0700 Subject: [PATCH] QLocale: cache the QLocalePrivate for QLocale::system() Change-Id: I6d0bf78d02d166307f864f1f83a3b600ef6a9b0b Reviewed-by: Konstantin Ritt Reviewed-by: Lars Knoll Reviewed-by: Edward Welbourne --- src/corelib/tools/qlocale.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/corelib/tools/qlocale.cpp b/src/corelib/tools/qlocale.cpp index d2254f5884..36e2dd52bf 100644 --- a/src/corelib/tools/qlocale.cpp +++ b/src/corelib/tools/qlocale.cpp @@ -661,6 +661,7 @@ static const QSystemLocale *systemLocale() void QLocalePrivate::updateSystemPrivate() { + // this function is NOT thread-safe! const QSystemLocale *sys_locale = systemLocale(); if (!system_data) system_data = &globalLocaleData; @@ -785,6 +786,8 @@ static const int locale_data_size = sizeof(locale_data)/sizeof(QLocaleData) - 1; Q_GLOBAL_STATIC_WITH_ARGS(QSharedDataPointer, defaultLocalePrivate, (QLocalePrivate::create(defaultData(), default_number_options))) +Q_GLOBAL_STATIC_WITH_ARGS(QSharedDataPointer, systemLocalePrivate, + (QLocalePrivate::create(systemData()))) static QLocalePrivate *localePrivateByName(const QString &name) { @@ -2343,7 +2346,9 @@ QString QLocale::toString(double i, char f, int prec) const QLocale QLocale::system() { - return QLocale(*QLocalePrivate::create(systemData())); + // this function is NOT thread-safe! + QT_PREPEND_NAMESPACE(systemData)(); // trigger updating of the system data if necessary + return QLocale(*systemLocalePrivate->data()); }