summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qhash.cpp
diff options
context:
space:
mode:
authorOswald Buddenhagen <oswald.buddenhagen@nokia.com>2010-02-16 12:00:07 (GMT)
committerOswald Buddenhagen <oswald.buddenhagen@nokia.com>2010-02-16 18:10:39 (GMT)
commit82027baa2c7705ae49300ce3ca0ac9eb4add2e96 (patch)
tree1a80c2a72b90c1dbe052dc9fc71c9b8959ab09ac /src/corelib/tools/qhash.cpp
parentc03b21d272f617b037ad9d0ccaa2f442638bf302 (diff)
downloadQt-82027baa2c7705ae49300ce3ca0ac9eb4add2e96.zip
Qt-82027baa2c7705ae49300ce3ca0ac9eb4add2e96.tar.gz
Qt-82027baa2c7705ae49300ce3ca0ac9eb4add2e96.tar.bz2
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
Diffstat (limited to 'src/corelib/tools/qhash.cpp')
-rw-r--r--src/corelib/tools/qhash.cpp12
1 files 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;
}