summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
authorAnton Kudryavtsev <a.kudryavtsev@netris.ru>2016-03-31 13:54:30 +0300
committerAnton Kudryavtsev <a.kudryavtsev@netris.ru>2016-03-31 13:31:04 +0000
commit32006535461d05d48bb8c63d27ed7e08215d7165 (patch)
treef3e143104e200304574e1015df84a656b078f356 /src/corelib
parent80d1e732d813c6101d1e7462b5685bd895807084 (diff)
QLocalePrivate: add overloaded codeToScript() and codeToLanguage()
... for QStringRef and QChar array. Now we can use QStringRef arg or QChar array arg to avoid unnecessary allocations. Also mark these functions as Q_DECL_NOTHROW. Change-Id: Ibe75346d80cc413e303fad886ecb82dbdb89af24 Reviewed-by: Edward Welbourne <edward.welbourne@theqtcompany.com> Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/tools/qlocale.cpp14
-rw-r--r--src/corelib/tools/qlocale_p.h8
2 files changed, 12 insertions, 10 deletions
diff --git a/src/corelib/tools/qlocale.cpp b/src/corelib/tools/qlocale.cpp
index 8d64e02814..e5a21dfef4 100644
--- a/src/corelib/tools/qlocale.cpp
+++ b/src/corelib/tools/qlocale.cpp
@@ -91,9 +91,8 @@ QT_BEGIN_INCLUDE_NAMESPACE
#include "qlocale_data_p.h"
QT_END_INCLUDE_NAMESPACE
-QLocale::Language QLocalePrivate::codeToLanguage(const QString &code)
+QLocale::Language QLocalePrivate::codeToLanguage(const QChar *code, int len) Q_DECL_NOTHROW
{
- int len = code.length();
if (len != 2 && len != 3)
return QLocale::C;
ushort uc1 = code[0].toLower().unicode();
@@ -134,17 +133,16 @@ QLocale::Language QLocalePrivate::codeToLanguage(const QString &code)
return QLocale::C;
}
-QLocale::Script QLocalePrivate::codeToScript(const QString &code)
+QLocale::Script QLocalePrivate::codeToScript(const QChar *code, int len) Q_DECL_NOTHROW
{
- int len = code.length();
if (len != 4)
return QLocale::AnyScript;
// script is titlecased in our data
- unsigned char c0 = code.at(0).toUpper().toLatin1();
- unsigned char c1 = code.at(1).toLower().toLatin1();
- unsigned char c2 = code.at(2).toLower().toLatin1();
- unsigned char c3 = code.at(3).toLower().toLatin1();
+ unsigned char c0 = code[0].toUpper().toLatin1();
+ unsigned char c1 = code[1].toLower().toLatin1();
+ unsigned char c2 = code[2].toLower().toLatin1();
+ unsigned char c3 = code[3].toLower().toLatin1();
const unsigned char *c = script_code_list;
for (int i = 0; i < QLocale::LastScript; ++i, c += 4) {
diff --git a/src/corelib/tools/qlocale_p.h b/src/corelib/tools/qlocale_p.h
index edffcea3e5..f95edf4d14 100644
--- a/src/corelib/tools/qlocale_p.h
+++ b/src/corelib/tools/qlocale_p.h
@@ -353,8 +353,12 @@ public:
static QString languageToCode(QLocale::Language language);
static QString scriptToCode(QLocale::Script script);
static QString countryToCode(QLocale::Country country);
- static QLocale::Language codeToLanguage(const QString &code);
- static QLocale::Script codeToScript(const QString &code);
+ static QLocale::Language codeToLanguage(const QChar *code, int len) Q_DECL_NOTHROW;
+ static QLocale::Language codeToLanguage(const QString &code) Q_DECL_NOTHROW { return codeToLanguage(code.data(), code.size()); }
+ static QLocale::Language codeToLanguage(const QStringRef &code) Q_DECL_NOTHROW { return codeToLanguage(code.data(), code.size()); }
+ static QLocale::Script codeToScript(const QChar *code, int len) Q_DECL_NOTHROW;
+ static QLocale::Script codeToScript(const QString &code) Q_DECL_NOTHROW { return codeToScript(code.data(), code.size()); }
+ static QLocale::Script codeToScript(const QStringRef &code) Q_DECL_NOTHROW { return codeToScript(code.data(), code.size()); }
static QLocale::Country codeToCountry(const QChar *code, int len) Q_DECL_NOTHROW;
static QLocale::Country codeToCountry(const QString &code) Q_DECL_NOTHROW { return codeToCountry(code.data(), code.size()); }
static QLocale::Country codeToCountry(const QStringRef &code) Q_DECL_NOTHROW { return codeToCountry(code.data(), code.size()); }