From d5020b89134cbb07e1aefe961168f9b2d9024618 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= Date: Tue, 27 Mar 2012 12:59:24 +0200 Subject: [PATCH] Use accumulating hash, instead of allocating intermediate string Change-Id: Ie93ac8df3066159ad11ff7f68c7ba85e7f5aa8bc Reviewed-by: Oswald Buddenhagen --- src/corelib/kernel/qtranslator.cpp | 21 +++++++++++++++++---- 1 file 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);