From 4d6572aac0eb1f75f3c810ce8e92635b956d29fc Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 25 Apr 2013 22:25:15 -0700 Subject: QLocale: cache the QLocalePrivate for the default QLocale Change-Id: I6f05da4d426a0aa685dd9f2fd0020e413a4bebad Reviewed-by: Lars Knoll --- src/corelib/tools/qlocale.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/corelib/tools/qlocale.cpp b/src/corelib/tools/qlocale.cpp index 57f9b22e53..991cc9e170 100644 --- a/src/corelib/tools/qlocale.cpp +++ b/src/corelib/tools/qlocale.cpp @@ -708,6 +708,9 @@ const QLocaleData *QLocalePrivate::dataPointerForIndex(quint16 index) return &locale_data[index]; } +Q_GLOBAL_STATIC_WITH_ARGS(QSharedDataPointer, defaultLocalePrivate, + (QLocalePrivate::create(defaultData(), default_number_options))) + static QLocalePrivate *localePrivateByName(const QString &name) { if (name == QLatin1String("C")) @@ -715,11 +718,6 @@ static QLocalePrivate *localePrivateByName(const QString &name) return QLocalePrivate::create(findLocaleData(name)); } -static QLocalePrivate *defaultLocalePrivate() -{ - return QLocalePrivate::create(defaultData(), default_number_options); -} - static QLocalePrivate *findLocalePrivate(QLocale::Language language, QLocale::Script script, QLocale::Country country) { @@ -790,7 +788,7 @@ QLocale::QLocale(const QString &name) */ QLocale::QLocale() - : d(defaultLocalePrivate()) + : d(*defaultLocalePrivate) { } @@ -1002,6 +1000,11 @@ void QLocale::setDefault(const QLocale &locale) { default_data = locale.d->m_data; default_number_options = locale.numberOptions(); + + if (defaultLocalePrivate.exists()) { + // update the cached private + *defaultLocalePrivate = locale.d; + } } /*! -- cgit v1.2.3