Changeset 69472 in webkit


Ignore:
Timestamp:
Oct 10, 2010 1:19:46 PM (14 years ago)
Author:
Patrick Gansterer
Message:

2010-10-10 Patrick Gansterer <Patrick Gansterer>

Reviewed by Adam Barth.

Use WTF::StringHasher in WTF::CaseFoldingHash
https://bugs.webkit.org/show_bug.cgi?id=46523

  • wtf/text/StringHash.h: (WTF::CaseFoldingHash::foldCase): (WTF::CaseFoldingHash::hash):
Location:
trunk/JavaScriptCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r69458 r69472  
     12010-10-10  Patrick Gansterer  <paroga@webkit.org>
     2
     3        Reviewed by Adam Barth.
     4
     5        Use WTF::StringHasher in WTF::CaseFoldingHash
     6        https://bugs.webkit.org/show_bug.cgi?id=46523
     7
     8        * wtf/text/StringHash.h:
     9        (WTF::CaseFoldingHash::foldCase):
     10        (WTF::CaseFoldingHash::hash):
     11
    1122010-10-09  Pratik Solanki  <psolanki@apple.com>
    213
  • trunk/JavaScriptCore/wtf/text/StringHash.h

    r66205 r69472  
    9797
    9898    class CaseFoldingHash {
     99        template<typename T> static inline UChar foldCase(T ch)
     100        {
     101            return WTF::Unicode::foldCase(ch);
     102        }
     103
    99104    public:
    100         // Paul Hsieh's SuperFastHash
    101         // http://www.azillionmonkeys.com/qed/hash.html
    102105        static unsigned hash(const UChar* data, unsigned length)
    103106        {
    104             unsigned l = length;
    105             const UChar* s = data;
    106             uint32_t hash = WTF::stringHashingStartValue;
    107             uint32_t tmp;
    108            
    109             int rem = l & 1;
    110             l >>= 1;
    111            
    112             // Main loop.
    113             for (; l > 0; l--) {
    114                 hash += WTF::Unicode::foldCase(s[0]);
    115                 tmp = (WTF::Unicode::foldCase(s[1]) << 11) ^ hash;
    116                 hash = (hash << 16) ^ tmp;
    117                 s += 2;
    118                 hash += hash >> 11;
    119             }
    120            
    121             // Handle end case.
    122             if (rem) {
    123                 hash += WTF::Unicode::foldCase(s[0]);
    124                 hash ^= hash << 11;
    125                 hash += hash >> 17;
    126             }
    127            
    128             // Force "avalanching" of final 127 bits.
    129             hash ^= hash << 3;
    130             hash += hash >> 5;
    131             hash ^= hash << 2;
    132             hash += hash >> 15;
    133             hash ^= hash << 10;
    134            
    135             // This avoids ever returning a hash code of 0, since that is used to
    136             // signal "hash not computed yet", using a value that is likely to be
    137             // effectively the same as 0 when the low bits are masked.
    138             hash |= !hash << 31;
    139            
    140             return hash;
     107            return StringHasher::createHash<UChar, foldCase>(data, length);
    141108        }
    142109
     
    145112            return hash(str->characters(), str->length());
    146113        }
    147        
    148         static unsigned hash(const char* str, unsigned length)
     114
     115        static unsigned hash(const char* data, unsigned length)
    149116        {
    150             // This hash is designed to work on 16-bit chunks at a time. But since the normal case
    151             // (above) is to hash UTF-16 characters, we just treat the 8-bit chars as if they
    152             // were 16-bit chunks, which will give matching results.
     117            return StringHasher::createHash<char, foldCase>(data, length);
     118        }
    153119
    154             unsigned l = length;
    155             const char* s = str;
    156             uint32_t hash = WTF::stringHashingStartValue;
    157             uint32_t tmp;
    158            
    159             int rem = l & 1;
    160             l >>= 1;
    161            
    162             // Main loop
    163             for (; l > 0; l--) {
    164                 hash += WTF::Unicode::foldCase(s[0]);
    165                 tmp = (WTF::Unicode::foldCase(s[1]) << 11) ^ hash;
    166                 hash = (hash << 16) ^ tmp;
    167                 s += 2;
    168                 hash += hash >> 11;
    169             }
    170            
    171             // Handle end case
    172             if (rem) {
    173                 hash += WTF::Unicode::foldCase(s[0]);
    174                 hash ^= hash << 11;
    175                 hash += hash >> 17;
    176             }
    177            
    178             // Force "avalanching" of final 127 bits
    179             hash ^= hash << 3;
    180             hash += hash >> 5;
    181             hash ^= hash << 2;
    182             hash += hash >> 15;
    183             hash ^= hash << 10;
    184            
    185             // this avoids ever returning a hash code of 0, since that is used to
    186             // signal "hash not computed yet", using a value that is likely to be
    187             // effectively the same as 0 when the low bits are masked
    188             hash |= !hash << 31;
    189            
    190             return hash;
    191         }
    192        
    193120        static bool equal(const StringImpl* a, const StringImpl* b)
    194121        {
Note: See TracChangeset for help on using the changeset viewer.