diff options
author | Ben Murdoch <benm@google.com> | 2010-10-22 13:02:20 +0100 |
---|---|---|
committer | Ben Murdoch <benm@google.com> | 2010-10-26 15:21:41 +0100 |
commit | a94275402997c11dd2e778633dacf4b7e630a35d (patch) | |
tree | e66f56c67e3b01f22c9c23cd932271ee9ac558ed /JavaScriptCore/wtf/text/StringHash.h | |
parent | 09e26c78506587b3f5d930d7bc72a23287ffbec0 (diff) | |
download | external_webkit-a94275402997c11dd2e778633dacf4b7e630a35d.zip external_webkit-a94275402997c11dd2e778633dacf4b7e630a35d.tar.gz external_webkit-a94275402997c11dd2e778633dacf4b7e630a35d.tar.bz2 |
Merge WebKit at r70209: Initial merge by Git
Change-Id: Id23a68efa36e9d1126bcce0b137872db00892c8e
Diffstat (limited to 'JavaScriptCore/wtf/text/StringHash.h')
-rw-r--r-- | JavaScriptCore/wtf/text/StringHash.h | 95 |
1 files changed, 11 insertions, 84 deletions
diff --git a/JavaScriptCore/wtf/text/StringHash.h b/JavaScriptCore/wtf/text/StringHash.h index bfd05eb..d7aabdb 100644 --- a/JavaScriptCore/wtf/text/StringHash.h +++ b/JavaScriptCore/wtf/text/StringHash.h @@ -26,7 +26,7 @@ #include "WTFString.h" #include <wtf/Forward.h> #include <wtf/HashTraits.h> -#include <wtf/StringHashFunctions.h> +#include <wtf/StringHasher.h> #include <wtf/unicode/Unicode.h> namespace WTF { @@ -97,99 +97,26 @@ namespace WTF { class CaseFoldingHash { public: - // Paul Hsieh's SuperFastHash - // http://www.azillionmonkeys.com/qed/hash.html + template<typename T> static inline UChar foldCase(T ch) + { + return WTF::Unicode::foldCase(ch); + } + static unsigned hash(const UChar* data, unsigned length) { - unsigned l = length; - const UChar* s = data; - uint32_t hash = WTF::stringHashingStartValue; - uint32_t tmp; - - int rem = l & 1; - l >>= 1; - - // Main loop. - for (; l > 0; l--) { - hash += WTF::Unicode::foldCase(s[0]); - tmp = (WTF::Unicode::foldCase(s[1]) << 11) ^ hash; - hash = (hash << 16) ^ tmp; - s += 2; - hash += hash >> 11; - } - - // Handle end case. - if (rem) { - hash += WTF::Unicode::foldCase(s[0]); - hash ^= hash << 11; - hash += hash >> 17; - } - - // Force "avalanching" of final 127 bits. - hash ^= hash << 3; - hash += hash >> 5; - hash ^= hash << 2; - hash += hash >> 15; - hash ^= hash << 10; - - // This avoids ever returning a hash code of 0, since that is used to - // signal "hash not computed yet", using a value that is likely to be - // effectively the same as 0 when the low bits are masked. - hash |= !hash << 31; - - return hash; + return StringHasher::createHash<UChar, foldCase<UChar> >(data, length); } static unsigned hash(StringImpl* str) { return hash(str->characters(), str->length()); } - - static unsigned hash(const char* str, unsigned length) - { - // This hash is designed to work on 16-bit chunks at a time. But since the normal case - // (above) is to hash UTF-16 characters, we just treat the 8-bit chars as if they - // were 16-bit chunks, which will give matching results. - unsigned l = length; - const char* s = str; - uint32_t hash = WTF::stringHashingStartValue; - uint32_t tmp; - - int rem = l & 1; - l >>= 1; - - // Main loop - for (; l > 0; l--) { - hash += WTF::Unicode::foldCase(s[0]); - tmp = (WTF::Unicode::foldCase(s[1]) << 11) ^ hash; - hash = (hash << 16) ^ tmp; - s += 2; - hash += hash >> 11; - } - - // Handle end case - if (rem) { - hash += WTF::Unicode::foldCase(s[0]); - hash ^= hash << 11; - hash += hash >> 17; - } - - // Force "avalanching" of final 127 bits - hash ^= hash << 3; - hash += hash >> 5; - hash ^= hash << 2; - hash += hash >> 15; - hash ^= hash << 10; - - // this avoids ever returning a hash code of 0, since that is used to - // signal "hash not computed yet", using a value that is likely to be - // effectively the same as 0 when the low bits are masked - hash |= !hash << 31; - - return hash; + static unsigned hash(const char* data, unsigned length) + { + return StringHasher::createHash<char, foldCase<char> >(data, length); } - + static bool equal(const StringImpl* a, const StringImpl* b) { if (a == b) |