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>
bb10
Marc Mutz 2014-08-09 11:19:43 +02:00 committed by Thiago Macieira
parent c250a0ec3a
commit 6dd759c8e9
1 changed files with 3 additions and 3 deletions

View File

@ -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;