diff options
author | Thiago Macieira <thiago.macieira@nokia.com> | 2009-03-19 13:45:41 (GMT) |
---|---|---|
committer | Thiago Macieira <thiago.macieira@nokia.com> | 2009-07-21 13:48:46 (GMT) |
commit | 52f5eee17a629fca785f79dcfc8b7bf0b23d1da2 (patch) | |
tree | 23bb1736d184e08b8563db0183d75cf1cb7fd66a /src/corelib | |
parent | 4c64137c6dfbfcc5a6fecbb04f5159ec491842e1 (diff) | |
download | Qt-52f5eee17a629fca785f79dcfc8b7bf0b23d1da2.zip Qt-52f5eee17a629fca785f79dcfc8b7bf0b23d1da2.tar.gz Qt-52f5eee17a629fca785f79dcfc8b7bf0b23d1da2.tar.bz2 |
Minor performance improvements in nameprepping.
Avoid calling functions that may have other side effects, like
QString::utf16(). Use pointers whenever possible when iterating over
the string.
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/io/qurl.cpp | 43 | ||||
-rw-r--r-- | src/corelib/tools/qchar.cpp | 10 |
2 files changed, 28 insertions, 25 deletions
diff --git a/src/corelib/io/qurl.cpp b/src/corelib/io/qurl.cpp index 78e314e..49c0d538 100644 --- a/src/corelib/io/qurl.cpp +++ b/src/corelib/io/qurl.cpp @@ -2913,56 +2913,59 @@ static bool qt_check_std3rules(const QChar *uc, int len); void qt_nameprep(QString *source, int from) { - QString &mapped = *source; - - for ( ; from < mapped.size(); ++from) { - ushort uc = mapped.at(from).unicode(); + QChar *src = source->data(); // causes a detach, so we're sure the only one using it + QChar *out = src + from; + const QChar *e = src + source->size(); + + for ( ; out < e; ++out) { + register ushort uc = out->unicode(); if (uc > 0x80) { break; } else if (uc >= 'A' && uc <= 'Z') { - mapped[from] = QChar(uc | 0x20); + *out = QChar(uc | 0x20); } } - if (from == mapped.size()) + if (out == e) return; // everything was mapped easily (lowercased, actually) - + int firstNonAscii = out - src; + // Characters commonly mapped to nothing are simply removed // (Table B.1) - QChar *out = mapped.data() + from; const QChar *in = out; - const QChar *e = mapped.constData() + mapped.size(); while (in < e) { if (!isMappedToNothing(*in)) *out++ = *in; ++in; } if (out != in) - mapped.truncate(out - mapped.constData()); + source->truncate(out - src); // Map to lowercase (Table B.2) - mapToLowerCase(&mapped, from); + mapToLowerCase(source, firstNonAscii); // Normalize to Unicode 3.2 form KC extern void qt_string_normalize(QString *data, QString::NormalizationForm mode, QChar::UnicodeVersion version, int from); - qt_string_normalize(&mapped, QString::NormalizationForm_KC, QChar::Unicode_3_2, from); + qt_string_normalize(source, QString::NormalizationForm_KC, QChar::Unicode_3_2, firstNonAscii); // Strip prohibited output - stripProhibitedOutput(&mapped, from); + stripProhibitedOutput(source, firstNonAscii); // Check for valid bidirectional characters bool containsLCat = false; bool containsRandALCat = false; - for (int j = from; j < mapped.size() && (!containsLCat || !containsRandALCat); ++j) { - if (isBidirectionalL(mapped.at(j))) + src = source->data(); + e = src + source->size(); + for (in = src + from; in < e && (!containsLCat || !containsRandALCat); ++in) { + if (isBidirectionalL(*in)) containsLCat = true; - else if (isBidirectionalRorAL(mapped.at(j))) + else if (isBidirectionalRorAL(*in)) containsRandALCat = true; } if (containsRandALCat) { - if (containsLCat || (!isBidirectionalRorAL(mapped.at(from)) - || !isBidirectionalRorAL(mapped.at(mapped.size() - 1)))) - mapped.clear(); + if (containsLCat || (!isBidirectionalRorAL(src[from]) + || !isBidirectionalRorAL(e[-1]))) + source->resize(from); // not allowed, clear the label } } @@ -3269,7 +3272,7 @@ static QString qt_ACE_do(const QString &domain, AceOperation op) // ACE form domains contain only ASCII characters, but we can't consider them simple // is this an ACE form? static const ushort acePrefixUtf16[] = { 'x', 'n', '-', '-' }; - if (memcmp(result.utf16() + prevLen, acePrefixUtf16, sizeof acePrefixUtf16) == 0) + if (memcmp(result.constData() + prevLen, acePrefixUtf16, sizeof acePrefixUtf16) == 0) simple = false; } diff --git a/src/corelib/tools/qchar.cpp b/src/corelib/tools/qchar.cpp index 1558f7d..458a383 100644 --- a/src/corelib/tools/qchar.cpp +++ b/src/corelib/tools/qchar.cpp @@ -1427,7 +1427,7 @@ static void decomposeHelper(QString *str, bool canonical, QChar::UnicodeVersion QString &s = *str; - const unsigned short *utf16 = s.utf16(); + const unsigned short *utf16 = reinterpret_cast<unsigned short *>(s.data()); const unsigned short *uc = utf16 + s.length(); while (uc != utf16 + from) { uint ucs4 = *(--uc); @@ -1449,7 +1449,7 @@ static void decomposeHelper(QString *str, bool canonical, QChar::UnicodeVersion s.replace(uc - utf16, ucs4 > 0x10000 ? 2 : 1, (const QChar *)d, length); // since the insert invalidates the pointers and we do decomposition recursive int pos = uc - utf16; - utf16 = s.utf16(); + utf16 = reinterpret_cast<unsigned short *>(s.data()); uc = utf16 + pos + length; } } @@ -1498,9 +1498,9 @@ static void composeHelper(QString *str, int from) int lastCombining = 0; int pos = from; while (pos < s.length()) { - uint uc = s.utf16()[pos]; + uint uc = s.at(pos).unicode(); if (QChar(uc).isHighSurrogate() && pos < s.length()-1) { - ushort low = s.utf16()[pos+1]; + ushort low = s.at(pos+1).unicode(); if (QChar(low).isLowSurrogate()) { uc = QChar::surrogateToUcs4(uc, low); ++pos; @@ -1509,7 +1509,7 @@ static void composeHelper(QString *str, int from) int combining = QChar::combiningClass(uc); if (starter == pos - 1 || combining > lastCombining) { // allowed to form ligature with S - QChar ligature = ligatureHelper(s.utf16()[starter], uc); + QChar ligature = ligatureHelper(s.at(starter).unicode(), uc); if (ligature.unicode()) { s[starter] = ligature; s.remove(pos, 1); |