diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2014-08-09 11:19:43 +0200 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2014-08-19 03:39:27 +0200 |
commit | 6dd759c8e947670f28dccba946138b7f8d609eaa (patch) | |
tree | 6abb72d3701554dec974c04831e9b02d482f1867 /src/corelib/tools/qbytearray.cpp | |
parent | c250a0ec3a196247dde372cde3757913226386b0 (diff) |
Optimize qstricmp()/qstrnicmp()
The latin1 conversion tables that were recently introduced to qbytearray.cpp
to speed up QByteArray::to{Upper,Lower}() can also be used in qstr(n)icmp.
This results in speedups between ~2 for strings with differences in the
first char, to almost 10x for strings with differences only after 8k of
data.
Change-Id: I878ddb4c01c798069d439a9d33e24351fe1039d3
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Diffstat (limited to 'src/corelib/tools/qbytearray.cpp')
-rw-r--r-- | src/corelib/tools/qbytearray.cpp | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/corelib/tools/qbytearray.cpp b/src/corelib/tools/qbytearray.cpp index 150da82cb8..6b6a9d2c1a 100644 --- a/src/corelib/tools/qbytearray.cpp +++ b/src/corelib/tools/qbytearray.cpp @@ -62,7 +62,7 @@ QT_BEGIN_NAMESPACE -// Latin 1 case system: +// Latin 1 case system, used by QByteArray::to{Upper,Lower}() and qstr(n)icmp(): /* #!/usr/bin/perl -l use feature "unicode_strings"; @@ -314,7 +314,7 @@ int qstricmp(const char *str1, const char *str2) uchar c; if (!s1 || !s2) return s1 ? 1 : (s2 ? -1 : 0); - for (; !(res = (c = QChar::toLower((ushort)*s1)) - QChar::toLower((ushort)*s2)); s1++, s2++) + for (; !(res = (c = latin1_lowercased[*s1]) - latin1_lowercased[*s2]); s1++, s2++) if (!c) // strings are equal break; return res; @@ -349,7 +349,7 @@ int qstrnicmp(const char *str1, const char *str2, uint len) if (!s1 || !s2) return s1 ? 1 : (s2 ? -1 : 0); for (; len--; s1++, s2++) { - if ((res = (c = QChar::toLower((ushort)*s1)) - QChar::toLower((ushort)*s2))) + if ((res = (c = latin1_lowercased[*s1]) - latin1_lowercased[*s2])) return res; if (!c) // strings are equal break; |