From 82027baa2c7705ae49300ce3ca0ac9eb4add2e96 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Tue, 16 Feb 2010 13:00:07 +0100 Subject: optimize qHash() some more on modern architectures, a longer data dependency chain is worse than a slightly bigger instruction. as it happens, the code is also clearer. would you have guessed that qHash() is only 28 bits wide? Reviewed-by: joao Reviewed-by: denis --- src/corelib/tools/qhash.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/corelib/tools/qhash.cpp b/src/corelib/tools/qhash.cpp index 285f4c9..85a8b63 100644 --- a/src/corelib/tools/qhash.cpp +++ b/src/corelib/tools/qhash.cpp @@ -64,13 +64,11 @@ QT_BEGIN_NAMESPACE static uint hash(const uchar *p, int n) { uint h = 0; - uint g; while (n--) { h = (h << 4) + *p++; - g = h & 0xf0000000; - h ^= g >> 23; - h &= ~g; + h ^= (h & 0xf0000000) >> 23; + h &= 0x0fffffff; } return h; } @@ -78,13 +76,11 @@ static uint hash(const uchar *p, int n) static uint hash(const QChar *p, int n) { uint h = 0; - uint g; while (n--) { h = (h << 4) + (*p++).unicode(); - g = h & 0xf0000000; - h ^= g >> 23; - h &= ~g; + h ^= (h & 0xf0000000) >> 23; + h &= 0x0fffffff; } return h; } -- cgit v0.12