summaryrefslogtreecommitdiffstats
path: root/tests/benchmarks/corelib/tools/qhash/outofline.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/benchmarks/corelib/tools/qhash/outofline.cpp')
-rw-r--r--tests/benchmarks/corelib/tools/qhash/outofline.cpp48
1 files changed, 9 insertions, 39 deletions
diff --git a/tests/benchmarks/corelib/tools/qhash/outofline.cpp b/tests/benchmarks/corelib/tools/qhash/outofline.cpp
index 162c604a35..75d99f96f8 100644
--- a/tests/benchmarks/corelib/tools/qhash/outofline.cpp
+++ b/tests/benchmarks/corelib/tools/qhash/outofline.cpp
@@ -41,49 +41,19 @@
#include "main.h"
-static void doHash(const unsigned short *p, uint &h)
-{
-#if 1
- // Copied from static uint hash(const QChar *p, int n).
- // Possibly not the cheapest way.
- h = (h << 4) + (*p++);
- h ^= (h & 0xf0000000) >> 23;
- h &= 0x0fffffff;
-
- h = (h << 4) + (*p++);
- h ^= (h & 0xf0000000) >> 23;
- h &= 0x0fffffff;
-
- h = (h << 4) + (*p++);
- h ^= (h & 0xf0000000) >> 23;
- h &= 0x0fffffff;
-
- h = (h << 4) + (*p++);
- h ^= (h & 0xf0000000) >> 23;
- h &= 0x0fffffff;
-#else
- // Faster, but probably less spread.
- h ^= *(unsigned int *)p;
-#endif
-}
-
QT_BEGIN_NAMESPACE
-uint qHash(const String &str)
+uint qHash(const Qt4String &str)
{
- const unsigned short *p = (unsigned short *)str.constData();
- const int s = str.size();
- switch (s) {
- case 0: return 0;
- case 1: return *p;
- case 2: return *(unsigned int *)p;
- case 3: return (*(unsigned int *)p) ^ *(p + 2);
- //case 3: return (*p << 11) + (*(p + 1) << 22) + *(p + 2);
- }
+ int n = str.length();
+ const QChar *p = str.unicode();
uint h = 0;
- doHash(p, h);
- doHash(p + s / 2 - 2, h);
- doHash(p + s - 4, h);
+
+ while (n--) {
+ h = (h << 4) + (*p++).unicode();
+ h ^= (h & 0xf0000000) >> 23;
+ h &= 0x0fffffff;
+ }
return h;
}