summaryrefslogtreecommitdiff
path: root/src/libs/3rdparty
diff options
context:
space:
mode:
authorChristian Kamm <christian.d.kamm@nokia.com>2011-09-07 08:45:01 +0200
committerChristian Kamm <christian.d.kamm@nokia.com>2011-09-07 09:32:24 +0200
commitc074b18f8d4510713f6d66149213510428eae6f1 (patch)
tree64a432b01ffce6f085a7c461ec72574888172a2f /src/libs/3rdparty
parentdcf835a587f1cae4d929b72a1c470dcdca9c81a2 (diff)
downloadqt-creator-c074b18f8d4510713f6d66149213510428eae6f1.tar.gz
C++: Improve Literal::hashCode.
This can have a dramatic impact on performance when a file contains lots of unique literals. Change-Id: I5309b28f704d7f53e164dc8084ae08354c09354b Reviewed-on: http://codereview.qt.nokia.com/4312 Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
Diffstat (limited to 'src/libs/3rdparty')
-rw-r--r--src/libs/3rdparty/cplusplus/Literals.cpp18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/libs/3rdparty/cplusplus/Literals.cpp b/src/libs/3rdparty/cplusplus/Literals.cpp
index 16eab541d7..d0aa05d351 100644
--- a/src/libs/3rdparty/cplusplus/Literals.cpp
+++ b/src/libs/3rdparty/cplusplus/Literals.cpp
@@ -75,9 +75,21 @@ unsigned Literal::hashCode() const
unsigned Literal::hashCode(const char *chars, unsigned size)
{
- unsigned h = 0;
- for (unsigned i = 0; i < size; ++i)
- h = (h >> 5) - h + chars[i];
+ /* Hash taken from QtCore's qHash for strings, which in turn has the note:
+
+ These functions are based on Peter J. Weinberger's hash function
+ (from the Dragon Book). The constant 24 in the original function
+ was replaced with 23 to produce fewer collisions on input such as
+ "a", "aa", "aaa", "aaaa", ...
+ */
+
+ uint h = 0;
+
+ while (size--) {
+ h = (h << 4) + *chars++;
+ h ^= (h & 0xf0000000) >> 23;
+ h &= 0x0fffffff;
+ }
return h;
}