Index: Source/wtf/HashFunctions.h |
diff --git a/Source/wtf/HashFunctions.h b/Source/wtf/HashFunctions.h |
index 75fabcd97ad02cea0bcff9ffbb836e80c7dfb93e..ee842c3f7225416b88712ec2250f2b1e98c3d802 100644 |
--- a/Source/wtf/HashFunctions.h |
+++ b/Source/wtf/HashFunctions.h |
@@ -32,57 +32,25 @@ namespace WTF { |
template<> struct IntTypes<4> { typedef int32_t SignedType; typedef uint32_t UnsignedType; }; |
template<> struct IntTypes<8> { typedef int64_t SignedType; typedef uint64_t UnsignedType; }; |
- // integer hash function |
- |
- // Thomas Wang's 32 Bit Mix Function: http://www.cris.com/~Ttwang/tech/inthash.htm |
inline unsigned intHash(uint8_t key8) |
{ |
- unsigned key = key8; |
- key += ~(key << 15); |
- key ^= (key >> 10); |
- key += (key << 3); |
- key ^= (key >> 6); |
- key += ~(key << 11); |
- key ^= (key >> 16); |
- return key; |
+ return key8; |
} |
- // Thomas Wang's 32 Bit Mix Function: http://www.cris.com/~Ttwang/tech/inthash.htm |
inline unsigned intHash(uint16_t key16) |
{ |
- unsigned key = key16; |
- key += ~(key << 15); |
- key ^= (key >> 10); |
- key += (key << 3); |
- key ^= (key >> 6); |
- key += ~(key << 11); |
- key ^= (key >> 16); |
- return key; |
+ return key16; |
} |
- // Thomas Wang's 32 Bit Mix Function: http://www.cris.com/~Ttwang/tech/inthash.htm |
inline unsigned intHash(uint32_t key) |
{ |
- key += ~(key << 15); |
- key ^= (key >> 10); |
- key += (key << 3); |
- key ^= (key >> 6); |
- key += ~(key << 11); |
- key ^= (key >> 16); |
- return key; |
+ return key ^ (key >> 16); |
} |
- |
- // Thomas Wang's 64 bit Mix Function: http://www.cris.com/~Ttwang/tech/inthash.htm |
+ |
inline unsigned intHash(uint64_t key) |
{ |
- key += ~(key << 32); |
- key ^= (key >> 22); |
- key += ~(key << 13); |
- key ^= (key >> 8); |
- key += (key << 3); |
- key ^= (key >> 15); |
- key += ~(key << 27); |
- key ^= (key >> 31); |
+ key ^= key >> 32; |
+ key ^= key >> 16; |
return static_cast<unsigned>(key); |
} |
@@ -126,7 +94,9 @@ namespace WTF { |
#pragma warning(push) |
#pragma warning(disable: 4244) // work around what seems to be a bug in MSVC's conversion warnings |
#endif |
- return IntHash<uintptr_t>::hash(reinterpret_cast<uintptr_t>(key)); |
+ uintptr_t keyIntPtr = reinterpret_cast<uintptr_t>(key); |
+ keyIntPtr ^= keyIntPtr >> 6; |
+ return IntHash<uintptr_t>::hash(keyIntPtr); |
#if COMPILER(MSVC) |
#pragma warning(pop) |
#endif |