summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qchar.cpp
diff options
context:
space:
mode:
authorKonstantin Ritt <ritt.ks@gmail.com>2012-04-10 18:00:32 +0300
committerQt by Nokia <qt-info@nokia.com>2012-04-19 15:57:38 +0200
commitf4d02ecdbf54987a0bada20fe8f8537e90c051d8 (patch)
tree2394b952271da1903c43aca85a993f26246fe7a0 /src/corelib/tools/qchar.cpp
parent73423db31d505e4101b446554c840e933c93f7df (diff)
optimize canonicalOrderHelper() for generic case
if there is no need to swap codepoints A and B, then we proceeding with advance to the next codepoint B that becomes A, and some next codepoint C becomes B; in such case we can easily skip the re-calculations for A by using previously calculated results for B Change-Id: I5c63589c274acaddf0f6a4cb1e0608d352a0c1b3 Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Diffstat (limited to 'src/corelib/tools/qchar.cpp')
-rw-r--r--src/corelib/tools/qchar.cpp26
1 files changed, 21 insertions, 5 deletions
diff --git a/src/corelib/tools/qchar.cpp b/src/corelib/tools/qchar.cpp
index e3d6c60b0f..1730418702 100644
--- a/src/corelib/tools/qchar.cpp
+++ b/src/corelib/tools/qchar.cpp
@@ -1526,10 +1526,14 @@ static void canonicalOrderHelper(QString *str, QChar::UnicodeVersion version, in
{
QString &s = *str;
const int l = s.length()-1;
+
+ uint u1, u2;
+ ushort c1, c2;
+
int pos = from;
while (pos < l) {
int p2 = pos+1;
- uint u1 = s.at(pos).unicode();
+ u1 = s.at(pos).unicode();
if (QChar(u1).isHighSurrogate()) {
ushort low = s.at(p2).unicode();
if (QChar(low).isLowSurrogate()) {
@@ -1539,7 +1543,10 @@ static void canonicalOrderHelper(QString *str, QChar::UnicodeVersion version, in
++p2;
}
}
- uint u2 = s.at(p2).unicode();
+ c1 = 0;
+
+ advance:
+ u2 = s.at(p2).unicode();
if (QChar(u2).isHighSurrogate() && p2 < l) {
ushort low = s.at(p2+1).unicode();
if (QChar(low).isLowSurrogate()) {
@@ -1548,7 +1555,7 @@ static void canonicalOrderHelper(QString *str, QChar::UnicodeVersion version, in
}
}
- ushort c2 = 0;
+ c2 = 0;
{
const QUnicodeTables::Properties *p = qGetProp(u2);
if (p->unicodeVersion <= version && p->unicodeVersion != QChar::Unicode_Unassigned)
@@ -1559,8 +1566,7 @@ static void canonicalOrderHelper(QString *str, QChar::UnicodeVersion version, in
continue;
}
- ushort c1 = 0;
- {
+ if (c1 == 0) {
const QUnicodeTables::Properties *p = qGetProp(u1);
if (p->unicodeVersion <= version && p->unicodeVersion != QChar::Unicode_Unassigned)
c1 = p->combiningClass;
@@ -1590,6 +1596,16 @@ static void canonicalOrderHelper(QString *str, QChar::UnicodeVersion version, in
++pos;
if (QChar::requiresSurrogates(u1))
++pos;
+
+ u1 = u2;
+ c1 = c2; // != 0
+ p2 = pos + 1;
+ if (QChar::requiresSurrogates(u1))
+ ++p2;
+ if (p2 > l)
+ break;
+
+ goto advance;
}
}
}