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/io/qurl.cpp | |
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/io/qurl.cpp')
-rw-r--r-- | src/corelib/io/qurl.cpp | 43 |
1 files changed, 23 insertions, 20 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; } |