From 5f049621326bd0236713263c71b0a78f8e7dff3f Mon Sep 17 00:00:00 2001 From: Konstantin Ritt Date: Tue, 18 Oct 2011 19:12:20 +0200 Subject: optimize QString::toLower()/toUpper() for special cases, step 1 reorganize QUnicodeTables::specialCaseMap as follows: specialCaseMap contains sequence entries in form { length, a, b, .. } Change-Id: Iea1f80bc2f4dc1f505428dad981cde26daaa52c7 Merge-request: 70 Reviewed-by: Oswald Buddenhagen Reviewed-by: Olivier Reviewed-by: Olivier Goffart --- util/unicode/main.cpp | 49 +++++++++++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 18 deletions(-) (limited to 'util') diff --git a/util/unicode/main.cpp b/util/unicode/main.cpp index 8ba992f72b..40294eba4d 100644 --- a/util/unicode/main.cpp +++ b/util/unicode/main.cpp @@ -472,17 +472,23 @@ static int appendToSpecialCaseMap(const QList &map) utf16map << val; } } - specialCaseMaxLen = qMax(specialCaseMaxLen, utf16map.size()); - utf16map << 0; - - for (int i = 0; i < specialCaseMap.size() - utf16map.size() + 1; ++i) { - int j; - for (j = 0; j < utf16map.size(); ++j) { - if (specialCaseMap.at(i+j) != utf16map.at(j)) - break; + int length = utf16map.size(); + utf16map.prepend(length); + specialCaseMaxLen = qMax(specialCaseMaxLen, length); + + int i = 0; + while (i < specialCaseMap.size()) { + int n = specialCaseMap.at(i); + if (n == length) { + int j; + for (j = 1; j <= n; ++j) { + if (specialCaseMap.at(i+j) != utf16map.at(j)) + break; + } + if (j > n) + return i; } - if (j == utf16map.size()) - return i; + i += n + 1; } int pos = specialCaseMap.size(); @@ -1528,7 +1534,8 @@ static inline void foldCase(uint ch, ushort *out) *(out++) = ch + p->caseFoldDiff; } else { const ushort *folded = specialCaseMap + p->caseFoldDiff; - while (*folded) + ushort length = *folded++; + while (length--) *out++ = *folded++; } *out = 0; @@ -2243,13 +2250,19 @@ static QByteArray createPropertyInfo() " return (QUnicodeTables::LineBreakClass)qGetProp(ucs4)->line_break_class;\n" "}\n\n"; - out += "static const ushort specialCaseMap[] = {\n "; - for (int i = 0; i < specialCaseMap.size(); ++i) { - out += QByteArray(" 0x") + QByteArray::number(specialCaseMap.at(i), 16); - if (i < specialCaseMap.size() - 1) - out += ","; - if (!specialCaseMap.at(i)) - out += "\n "; + + out += "static const ushort specialCaseMap[] = {"; + int i = 0; + while (i < specialCaseMap.size()) { + out += "\n "; + int n = specialCaseMap.at(i); + int j; + for (j = 0; j <= n; ++j) { + out += QByteArray(" 0x") + QByteArray::number(specialCaseMap.at(i+j), 16); + if (i+j < specialCaseMap.size() - 1) + out += ","; + } + i += n + 1; } out += "\n};\n"; out += "#define SPECIAL_CASE_MAX_LEN " + QByteArray::number(specialCaseMaxLen) + "\n\n"; -- cgit v1.2.3