diff options
author | Thiago Macieira <thiago.macieira@nokia.com> | 2009-03-19 14:46:32 (GMT) |
---|---|---|
committer | Thiago Macieira <thiago.macieira@nokia.com> | 2009-07-21 13:48:46 (GMT) |
commit | ff1280178ac8739e5943fd081be5317b70717fa8 (patch) | |
tree | 54f76d02d5d55e3d4e92fac3296fff7344058237 /src/corelib/io/qurl.cpp | |
parent | f15d4e5e02e109003b6e28cad71441f19b6ea608 (diff) | |
download | Qt-ff1280178ac8739e5943fd081be5317b70717fa8.zip Qt-ff1280178ac8739e5943fd081be5317b70717fa8.tar.gz Qt-ff1280178ac8739e5943fd081be5317b70717fa8.tar.bz2 |
Merge the memcpy with the lowercasing and the non-ASCII detection.
This gives a 5% improvement in performance by avoiding iterating over
the contents more than once.
Diffstat (limited to 'src/corelib/io/qurl.cpp')
-rw-r--r-- | src/corelib/io/qurl.cpp | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/src/corelib/io/qurl.cpp b/src/corelib/io/qurl.cpp index 096e37e..79cd2f0 100644 --- a/src/corelib/io/qurl.cpp +++ b/src/corelib/io/qurl.cpp @@ -3255,23 +3255,25 @@ static QString qt_ACE_do(const QString &domain, AceOperation op) // 8. Verify that the number of code points is in the range 1 to 63 // inclusive. + // copy the label to the destination, which also serves as our scratch area, lowercasing it + int prevLen = result.size(); bool simple = true; - for (int i = lastIdx; i < idx; ++i) { - ushort ch = domain.at(i).unicode(); - if (ch > 0x7f) { - simple = false; - break; + result.resize(prevLen + labelLength); + { + QChar *out = result.data() + prevLen; + const QChar *in = domain.constData() + lastIdx; + const QChar *e = in + labelLength; + for (; in < e; ++in, ++out) { + register ushort uc = in->unicode(); + if (uc > 0x7f) + simple = false; + if (uc >= 'A' && uc <= 'Z') + *out = QChar(uc | 0x20); + else + *out = *in; } } - // copy the label to the destination, which also serves as our scratch area - // then nameprep it (in the case of "simple", it will cause a simple lowercasing) - int prevLen = result.size(); - result.resize(prevLen + labelLength); - memcpy(result.data() + prevLen, domain.constData() + lastIdx, labelLength * sizeof(QChar)); - qt_nameprep(&result, prevLen); - labelLength = result.length() - prevLen; - if (simple && labelLength > 6) { // ACE form domains contain only ASCII characters, but we can't consider them simple // is this an ACE form? @@ -3289,6 +3291,8 @@ static QString qt_ACE_do(const QString &domain, AceOperation op) } else { // Punycode encoding and decoding cannot be done in-place // That means we need one or two temporaries + qt_nameprep(&result, prevLen); + labelLength = result.length() - prevLen; register int toReserve = labelLength + 4 + 6; // "xn--" plus some extra bytes if (toReserve > aceForm.capacity()) aceForm.reserve(toReserve); |