From 6dd759c8e947670f28dccba946138b7f8d609eaa Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sat, 9 Aug 2014 11:19:43 +0200 Subject: 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 Reviewed-by: Olivier Goffart --- src/corelib/tools/qbytearray.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/corelib/tools/qbytearray.cpp') 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; -- cgit v1.2.3