From 50ab31a5dfe491510e194e58075b648fd0b47e6a Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 25 Apr 2013 22:19:02 -0700 Subject: [PATCH] QLocalePrivate: remove QLocalePrivate::m_index MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It's not used anywhere, so we don't need to cache the locale data index. We already have the pointer to the QLocaleData anyway. This saves us a few roundtrips calculating the index from the data pointer only to get the data pointer again. Change-Id: I6905d20a382ddcb9fb04cc886a17499b467f905a Reviewed-by: Robin Burchell Reviewed-by: Lars Knoll Reviewed-by: Jędrzej Nowacki --- src/corelib/tools/qlocale.cpp | 29 +++++++---------------------- src/corelib/tools/qlocale_p.h | 8 +++----- 2 files changed, 10 insertions(+), 27 deletions(-) diff --git a/src/corelib/tools/qlocale.cpp b/src/corelib/tools/qlocale.cpp index 27ad847611..a8b2b9fedb 100644 --- a/src/corelib/tools/qlocale.cpp +++ b/src/corelib/tools/qlocale.cpp @@ -699,45 +699,30 @@ const QLocaleData *QLocalePrivate::dataPointerForIndex(quint16 index) return &locale_data[index]; } -static quint16 localeDataIndex(const QLocaleData *p) -{ -#ifndef QT_NO_SYSTEMLOCALE - Q_ASSERT((p >= locale_data && p - locale_data < locale_data_size) - || (p != 0 && p == system_data)); - quint16 index = p == system_data ? locale_data_size : p - locale_data; -#else - Q_ASSERT(p >= locale_data && p - locale_data < locale_data_size); - quint16 index = p - locale_data; -#endif - - return index; -} static QLocalePrivate *localePrivateByName(const QString &name) { - return new QLocalePrivate(localeDataIndex(findLocaleData(name))); + return new QLocalePrivate(findLocaleData(name)); } static QLocalePrivate *defaultLocalePrivate() { - return new QLocalePrivate(localeDataIndex(defaultData()), default_number_options); + return new QLocalePrivate(defaultData(), default_number_options); } static QLocalePrivate *findLocalePrivate(QLocale::Language language, QLocale::Script script, QLocale::Country country) { const QLocaleData *data = QLocaleData::findLocaleData(language, script, country); - int index; + int numberOptions = 0; // If not found, should default to system if (data->m_language_id == QLocale::C && language != QLocale::C) { numberOptions = default_number_options; - index = localeDataIndex(defaultData()); - } else { - index = localeDataIndex(data); + data = defaultData(); } - return new QLocalePrivate(index, numberOptions); + return new QLocalePrivate(data, numberOptions); } @@ -2123,7 +2108,7 @@ QString QLocale::toString(double i, char f, int prec) const QLocale QLocale::system() { - return QLocale(*new QLocalePrivate(localeDataIndex(systemData()))); + return QLocale(*new QLocalePrivate(systemData())); } @@ -2158,7 +2143,7 @@ QList QLocale::matchingLocales(QLocale::Language language, && (language == QLocale::AnyLanguage || data->m_language_id == uint(language))) { if ((script == QLocale::AnyScript || data->m_script_id == uint(script)) && (country == QLocale::AnyCountry || data->m_country_id == uint(country))) { - QLocale locale(*new QLocalePrivate(localeDataIndex(data))); + QLocale locale(*new QLocalePrivate(data)); result.append(locale); } ++data; diff --git a/src/corelib/tools/qlocale_p.h b/src/corelib/tools/qlocale_p.h index 9674342307..9ed1b6bf76 100644 --- a/src/corelib/tools/qlocale_p.h +++ b/src/corelib/tools/qlocale_p.h @@ -208,10 +208,9 @@ public: class Q_CORE_EXPORT QLocalePrivate : public QSharedData { public: - explicit QLocalePrivate(int index, int numberOptions = 0) - : m_index(index), m_numberOptions(numberOptions) + explicit QLocalePrivate(const QLocaleData *data, int numberOptions = 0) + : m_data(data), m_numberOptions(numberOptions) { - m_data = dataPointerForIndex(index); } ~QLocalePrivate() @@ -332,9 +331,8 @@ public: QString dateTimeToString(const QString &format, const QDate *date, const QTime *time, const QLocale *q) const; - quint16 m_index; - quint16 m_numberOptions; const QLocaleData *m_data; + quint16 m_numberOptions; }; inline char QLocalePrivate::digitToCLocale(QChar in) const