QLocale: cache the QLocalePrivate for QLocale::system()

Change-Id: I6d0bf78d02d166307f864f1f83a3b600ef6a9b0b
Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
bb10
Thiago Macieira 2013-04-25 22:28:13 -07:00 committed by Edward Welbourne
parent 941184bd64
commit 5da8e5ddd4
1 changed files with 6 additions and 1 deletions

View File

@ -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<QLocalePrivate>, defaultLocalePrivate,
(QLocalePrivate::create(defaultData(), default_number_options)))
Q_GLOBAL_STATIC_WITH_ARGS(QSharedDataPointer<QLocalePrivate>, 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());
}