QLocale: cache the C locale's private

Change-Id: I81bbfeffebb5b7fc29d67bb7127beaf13838ac9f
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
This commit is contained in:
Thiago Macieira 2013-04-25 21:50:18 -07:00 committed by The Qt Project
parent a2f59955ae
commit 30a8d73fdc
2 changed files with 15 additions and 1 deletions

View File

@ -529,6 +529,9 @@ int qt_repeatCount(const QString &s, int i)
static const QLocaleData *default_data = 0; static const QLocaleData *default_data = 0;
static uint default_number_options = 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 #ifndef QT_NO_SYSTEMLOCALE
@ -643,6 +646,12 @@ static const QLocaleData *defaultData()
return default_data; 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 QString getLocaleListData(const ushort *data, int size, int index)
{ {
static const ushort separator = ';'; static const ushort separator = ';';
@ -699,9 +708,10 @@ const QLocaleData *QLocalePrivate::dataPointerForIndex(quint16 index)
return &locale_data[index]; return &locale_data[index];
} }
static QLocalePrivate *localePrivateByName(const QString &name) static QLocalePrivate *localePrivateByName(const QString &name)
{ {
if (name == QLatin1String("C"))
return &c_private;
return QLocalePrivate::create(findLocaleData(name)); return QLocalePrivate::create(findLocaleData(name));
} }
@ -713,6 +723,9 @@ static QLocalePrivate *defaultLocalePrivate()
static QLocalePrivate *findLocalePrivate(QLocale::Language language, QLocale::Script script, static QLocalePrivate *findLocalePrivate(QLocale::Language language, QLocale::Script script,
QLocale::Country country) QLocale::Country country)
{ {
if (language == QLocale::C)
return &c_private;
const QLocaleData *data = QLocaleData::findLocaleData(language, script, country); const QLocaleData *data = QLocaleData::findLocaleData(language, script, country);
int numberOptions = 0; int numberOptions = 0;

View File

@ -164,6 +164,7 @@ public:
static const QLocaleData *findLocaleData(QLocale::Language language, static const QLocaleData *findLocaleData(QLocale::Language language,
QLocale::Script script, QLocale::Script script,
QLocale::Country country); QLocale::Country country);
static const QLocaleData *c();
quint16 m_language_id, m_script_id, m_country_id; quint16 m_language_id, m_script_id, m_country_id;