summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qtranslator.cpp
diff options
context:
space:
mode:
authorJoão Abecasis <joao.abecasis@nokia.com>2012-03-27 12:59:24 +0200
committerQt by Nokia <qt-info@nokia.com>2012-03-28 00:44:20 +0200
commitd5020b89134cbb07e1aefe961168f9b2d9024618 (patch)
tree2cfcbf58ab9688c4ebfdb9a2e21bcc86946d1572 /src/corelib/kernel/qtranslator.cpp
parent2e92714090f19c9a1f47565e8b6eecceb0a50425 (diff)
Use accumulating hash, instead of allocating intermediate string
Change-Id: Ie93ac8df3066159ad11ff7f68c7ba85e7f5aa8bc Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@nokia.com>
Diffstat (limited to 'src/corelib/kernel/qtranslator.cpp')
-rw-r--r--src/corelib/kernel/qtranslator.cpp21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/corelib/kernel/qtranslator.cpp b/src/corelib/kernel/qtranslator.cpp
index 0bb4c3ce8b..284176dc9b 100644
--- a/src/corelib/kernel/qtranslator.cpp
+++ b/src/corelib/kernel/qtranslator.cpp
@@ -101,10 +101,9 @@ static bool match(const uchar* found, const char* target, uint len)
return (memcmp(found, target, len) == 0 && target[len] == '\0');
}
-static uint elfHash(const char *name)
+static void elfHash_continue(const char *name, uint &h)
{
const uchar *k;
- uint h = 0;
uint g;
if (name) {
@@ -116,9 +115,20 @@ static uint elfHash(const char *name)
h &= ~g;
}
}
+}
+
+static void elfHash_finish(uint &h)
+{
if (!h)
h = 1;
- return h;
+}
+
+static uint elfHash(const char *name)
+{
+ uint hash = 0;
+ elfHash_continue(name, hash);
+ elfHash_finish(hash);
+ return hash;
}
static int numerusHelper(int n, const uchar *rules, int rulesSize)
@@ -830,7 +840,10 @@ QString QTranslatorPrivate::do_translate(const char *context, const char *source
numerus = numerusHelper(n, numerusRulesArray, numerusRulesLength);
for (;;) {
- quint32 h = elfHash(QByteArray(QByteArray(sourceText) + comment).constData());
+ quint32 h = 0;
+ elfHash_continue(sourceText, h);
+ elfHash_continue(comment, h);
+ elfHash_finish(h);
const uchar *start = offsetArray;
const uchar *end = start + ((numItems-1) << 3);