From 600c538cd6001c6729d5a7dd687d2ad42bf6a7de Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 25 Apr 2013 21:43:21 -0700 Subject: Move the code that creates QLocalePrivate to separate functions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Direct benefit is that the code between the two QLocale constructors taking language, country and (maybe) scripts is merged. This will also allow us to cache the QLocale::c() result. Change-Id: Ia46c5a37764dc287bfcd3a52a022ac413c53a582 Reviewed-by: Robin Burchell Reviewed-by: Jędrzej Nowacki Reviewed-by: Lars Knoll --- src/corelib/tools/qlocale.cpp | 60 ++++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 27 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/tools/qlocale.cpp b/src/corelib/tools/qlocale.cpp index b5f983899a..27ad847611 100644 --- a/src/corelib/tools/qlocale.cpp +++ b/src/corelib/tools/qlocale.cpp @@ -713,6 +713,34 @@ static quint16 localeDataIndex(const QLocaleData *p) return index; } +static QLocalePrivate *localePrivateByName(const QString &name) +{ + return new QLocalePrivate(localeDataIndex(findLocaleData(name))); +} + +static QLocalePrivate *defaultLocalePrivate() +{ + return new QLocalePrivate(localeDataIndex(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); + } + return new QLocalePrivate(index, numberOptions); +} + + /*! \internal */ @@ -751,7 +779,7 @@ QLocale::QLocale(QLocalePrivate &dd) */ QLocale::QLocale(const QString &name) - : d(new QLocalePrivate(localeDataIndex(findLocaleData(name)))) + : d(localePrivateByName(name)) { } @@ -764,7 +792,7 @@ QLocale::QLocale(const QString &name) */ QLocale::QLocale() - : d(new QLocalePrivate(localeDataIndex(defaultData()), default_number_options)) + : d(defaultLocalePrivate()) { } @@ -788,21 +816,10 @@ QLocale::QLocale() */ QLocale::QLocale(Language language, Country country) + : d(findLocalePrivate(language, QLocale::AnyScript, country)) { - const QLocaleData *data = QLocaleData::findLocaleData(language, QLocale::AnyScript, 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); - } - d = new QLocalePrivate(index, numberOptions); } -\ + /*! \since 4.8 @@ -828,19 +845,8 @@ QLocale::QLocale(Language language, Country country) */ QLocale::QLocale(Language language, Script script, Country country) + : d(findLocalePrivate(language, script, 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); - } - d = new QLocalePrivate(index, numberOptions); } /*! -- cgit v1.2.3