QLocale: cache the QLocalePrivate for the default QLocale

Change-Id: I6f05da4d426a0aa685dd9f2fd0020e413a4bebad
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
This commit is contained in:
Thiago Macieira 2013-04-25 22:25:15 -07:00 committed by The Qt Project
parent 30a8d73fdc
commit 4d6572aac0

View File

@ -708,6 +708,9 @@ const QLocaleData *QLocalePrivate::dataPointerForIndex(quint16 index)
return &locale_data[index]; return &locale_data[index];
} }
Q_GLOBAL_STATIC_WITH_ARGS(QSharedDataPointer<QLocalePrivate>, defaultLocalePrivate,
(QLocalePrivate::create(defaultData(), default_number_options)))
static QLocalePrivate *localePrivateByName(const QString &name) static QLocalePrivate *localePrivateByName(const QString &name)
{ {
if (name == QLatin1String("C")) if (name == QLatin1String("C"))
@ -715,11 +718,6 @@ static QLocalePrivate *localePrivateByName(const QString &name)
return QLocalePrivate::create(findLocaleData(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, static QLocalePrivate *findLocalePrivate(QLocale::Language language, QLocale::Script script,
QLocale::Country country) QLocale::Country country)
{ {
@ -790,7 +788,7 @@ QLocale::QLocale(const QString &name)
*/ */
QLocale::QLocale() QLocale::QLocale()
: d(defaultLocalePrivate()) : d(*defaultLocalePrivate)
{ {
} }
@ -1002,6 +1000,11 @@ void QLocale::setDefault(const QLocale &locale)
{ {
default_data = locale.d->m_data; default_data = locale.d->m_data;
default_number_options = locale.numberOptions(); default_number_options = locale.numberOptions();
if (defaultLocalePrivate.exists()) {
// update the cached private
*defaultLocalePrivate = locale.d;
}
} }
/*! /*!