summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKonstantin Ritt <ritt.ks@gmail.com>2010-11-29 17:47:04 (GMT)
committerThiago Macieira <thiago.macieira@nokia.com>2010-11-29 17:52:33 (GMT)
commit3408dd34340ba7570feebcf09dbec9fb8db15736 (patch)
tree46a6d02f922e1f849737c1e3094b05b653b4cba6
parent3f314cb73b9404ac899d503c1ec16aeafe33ea4b (diff)
downloadQt-3408dd34340ba7570feebcf09dbec9fb8db15736.zip
Qt-3408dd34340ba7570feebcf09dbec9fb8db15736.tar.gz
Qt-3408dd34340ba7570feebcf09dbec9fb8db15736.tar.bz2
minor optimization: decrease amount of possible detaches to 1
Merge-request: 2503 Reviewed-by: Thiago Macieira <thiago.macieira@nokia.com>
-rw-r--r--src/corelib/tools/qstring.cpp16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp
index c30af64..36b01d2 100644
--- a/src/corelib/tools/qstring.cpp
+++ b/src/corelib/tools/qstring.cpp
@@ -6261,28 +6261,32 @@ void qt_string_normalize(QString *data, QString::NormalizationForm mode, QChar::
if (version == QChar::Unicode_Unassigned) {
version = UNICODE_DATA_VERSION;
} else if (version != UNICODE_DATA_VERSION) {
- QString &s = *data;
+ const QString &s = *data;
+ QChar *d = 0;
for (int i = 0; i < NumNormalizationCorrections; ++i) {
const NormalizationCorrection &n = uc_normalization_corrections[i];
if (n.version > version) {
int pos = from;
- if (n.ucs4 > 0xffff) {
+ if (QChar::requiresSurrogates(n.ucs4)) {
ushort ucs4High = QChar::highSurrogate(n.ucs4);
ushort ucs4Low = QChar::lowSurrogate(n.ucs4);
ushort oldHigh = QChar::highSurrogate(n.old_mapping);
ushort oldLow = QChar::lowSurrogate(n.old_mapping);
while (pos < s.length() - 1) {
if (s.at(pos).unicode() == ucs4High && s.at(pos + 1).unicode() == ucs4Low) {
- s[pos] = oldHigh;
- s[pos + 1] = oldLow;
- ++pos;
+ if (!d)
+ d = data->data();
+ d[pos] = QChar(oldHigh);
+ d[++pos] = QChar(oldLow);
}
++pos;
}
} else {
while (pos < s.length()) {
if (s.at(pos).unicode() == n.ucs4) {
- s[pos] = n.old_mapping;
+ if (!d)
+ d = data->data();
+ d[pos] = QChar(n.old_mapping);
}
++pos;
}