[SCM] WebKit Debian packaging branch, webkit-1.2, updated. upstream/1.1.90-6072-g9a69373

barraclough at apple.com barraclough at apple.com
Thu Apr 8 00:53:49 UTC 2010


The following commit has been merged in the webkit-1.2 branch:
commit f56b74920db0286f87b248ce24bce322e805e380
Author: barraclough at apple.com <barraclough at apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Mon Jan 4 22:00:38 2010 +0000

    JavaScriptCore: https://bugs.webkit.org/show_bug.cgi?id=33163
    Add string hashing functions to WTF.
    Use WTF's string hashing functions from UStringImpl.
    
    Reviewed by Sam Weinig.
    
    * JavaScriptCore.exp:
    * runtime/UStringImpl.cpp:
    * runtime/UStringImpl.h:
    (JSC::UStringImpl::computeHash):
    * wtf/HashFunctions.h:
    (WTF::stringHash):
    
    WebCore: https://bugs.webkit.org/show_bug.cgi?id=33163
    Use WTF's string hashing functions from StringImpl.
    
    Reviewed by Sam Weinig.
    
    * platform/text/StringImpl.h:
    (WebCore::StringImpl::computeHash):
    
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@52758 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/JavaScriptCore/ChangeLog b/JavaScriptCore/ChangeLog
index 944f2d8..9c1dd95 100644
--- a/JavaScriptCore/ChangeLog
+++ b/JavaScriptCore/ChangeLog
@@ -1,5 +1,20 @@
 2010-01-04  Gavin Barraclough  <barraclough at apple.com>
 
+        Reviewed by Sam Weinig.
+
+        https://bugs.webkit.org/show_bug.cgi?id=33163
+        Add string hashing functions to WTF.
+        Use WTF's string hashing functions from UStringImpl.
+
+        * JavaScriptCore.exp:
+        * runtime/UStringImpl.cpp:
+        * runtime/UStringImpl.h:
+        (JSC::UStringImpl::computeHash):
+        * wtf/HashFunctions.h:
+        (WTF::stringHash):
+
+2010-01-04  Gavin Barraclough  <barraclough at apple.com>
+
         Reviewed by Sam "Shimmey Shimmey" Weinig.
 
         https://bugs.webkit.org/show_bug.cgi?id=33158
diff --git a/JavaScriptCore/JavaScriptCore.exp b/JavaScriptCore/JavaScriptCore.exp
index 30b174c..4a87e4e 100644
--- a/JavaScriptCore/JavaScriptCore.exp
+++ b/JavaScriptCore/JavaScriptCore.exp
@@ -103,8 +103,6 @@ __ZN3JSC10throwErrorEPNS_9ExecStateENS_9ErrorTypeERKNS_7UStringE
 __ZN3JSC11JSByteArray15createStructureENS_7JSValueE
 __ZN3JSC11JSByteArrayC1EPNS_9ExecStateEN3WTF17NonNullPassRefPtrINS_9StructureEEEPNS3_9ByteArrayEPKNS_9ClassInfoE
 __ZN3JSC11ParserArena5resetEv
-__ZN3JSC11UStringImpl11computeHashEPKci
-__ZN3JSC11UStringImpl11computeHashEPKti
 __ZN3JSC11UStringImpl12sharedBufferEv
 __ZN3JSC11UStringImpl6s_nullE
 __ZN3JSC11UStringImpl7destroyEv
diff --git a/JavaScriptCore/runtime/UStringImpl.cpp b/JavaScriptCore/runtime/UStringImpl.cpp
index fa9abe6..4288624 100644
--- a/JavaScriptCore/runtime/UStringImpl.cpp
+++ b/JavaScriptCore/runtime/UStringImpl.cpp
@@ -81,97 +81,4 @@ void UStringImpl::destroy()
     delete this;
 }
 
-// Golden ratio - arbitrary start value to avoid mapping all 0's to all 0's
-// or anything like that.
-const unsigned PHI = 0x9e3779b9U;
-
-// Paul Hsieh's SuperFastHash
-// http://www.azillionmonkeys.com/qed/hash.html
-unsigned UStringImpl::computeHash(const UChar* s, int len)
-{
-    unsigned l = len;
-    uint32_t hash = PHI;
-    uint32_t tmp;
-
-    int rem = l & 1;
-    l >>= 1;
-
-    // Main loop
-    for (; l > 0; l--) {
-        hash += s[0];
-        tmp = (s[1] << 11) ^ hash;
-        hash = (hash << 16) ^ tmp;
-        s += 2;
-        hash += hash >> 11;
-    }
-
-    // Handle end case
-    if (rem) {
-        hash += 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
-    if (hash == 0)
-        hash = 0x80000000;
-
-    return hash;
-}
-
-// Paul Hsieh's SuperFastHash
-// http://www.azillionmonkeys.com/qed/hash.html
-unsigned UStringImpl::computeHash(const char* s, int l)
-{
-    // 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 should give matching results
-
-    uint32_t hash = PHI;
-    uint32_t tmp;
-
-    size_t rem = l & 1;
-    l >>= 1;
-
-    // Main loop
-    for (; l > 0; l--) {
-        hash += static_cast<unsigned char>(s[0]);
-        tmp = (static_cast<unsigned char>(s[1]) << 11) ^ hash;
-        hash = (hash << 16) ^ tmp;
-        s += 2;
-        hash += hash >> 11;
-    }
-
-    // Handle end case
-    if (rem) {
-        hash += static_cast<unsigned char>(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
-    if (hash == 0)
-        hash = 0x80000000;
-
-    return hash;
-}
-
 }
diff --git a/JavaScriptCore/runtime/UStringImpl.h b/JavaScriptCore/runtime/UStringImpl.h
index 792b25a..256f731 100644
--- a/JavaScriptCore/runtime/UStringImpl.h
+++ b/JavaScriptCore/runtime/UStringImpl.h
@@ -27,6 +27,7 @@
 #define UStringImpl_h
 
 #include <wtf/CrossThreadRefCounted.h>
+#include <wtf/HashFunctions.h>
 #include <wtf/OwnFastMallocPtr.h>
 #include <wtf/PossiblyNull.h>
 #include <wtf/unicode/Unicode.h>
@@ -159,9 +160,9 @@ public:
             memcpy(destination, source, numCharacters * sizeof(UChar));
     }
 
-    static unsigned computeHash(const UChar*, int length);
-    static unsigned computeHash(const char*, int length);
-    static unsigned computeHash(const char* s) { return computeHash(s, strlen(s)); }
+    static unsigned computeHash(const UChar* s, int length) { ASSERT(length >= 0); return WTF::stringHash(s, length); }
+    static unsigned computeHash(const char* s, int length) { ASSERT(length >= 0); return WTF::stringHash(s, length); }
+    static unsigned computeHash(const char* s) { return WTF::stringHash(s); }
 
     static UStringImpl& null() { return *s_null; }
     static UStringImpl& empty() { return *s_empty; }
diff --git a/JavaScriptCore/wtf/HashFunctions.h b/JavaScriptCore/wtf/HashFunctions.h
index 13afb72..16de16f 100644
--- a/JavaScriptCore/wtf/HashFunctions.h
+++ b/JavaScriptCore/wtf/HashFunctions.h
@@ -22,6 +22,7 @@
 #define WTF_HashFunctions_h
 
 #include "RefPtr.h"
+#include "wtf/unicode/Unicode.h"
 #include <stdint.h>
 
 namespace WTF {
@@ -177,6 +178,125 @@ namespace WTF {
     // Golden ratio - arbitrary start value to avoid mapping all 0's to all 0's
     static const unsigned stringHashingStartValue = 0x9e3779b9U;
 
+    // stringHash methods based on Paul Hsieh's SuperFastHash.
+    // http://www.azillionmonkeys.com/qed/hash.html
+    // char* data is interpreted as latin-encoded (zero extended to 16 bits).
+
+    inline unsigned stringHash(const UChar* data, unsigned length)
+    {
+        unsigned hash = WTF::stringHashingStartValue;
+        unsigned rem = length & 1;
+        length >>= 1;
+
+        // Main loop
+        for (; length > 0; length--) {
+            hash += data[0];
+            unsigned tmp = (data[1] << 11) ^ hash;
+            hash = (hash << 16) ^ tmp;
+            data += 2;
+            hash += hash >> 11;
+        }
+
+        // Handle end case
+        if (rem) {
+            hash += data[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
+        if (hash == 0)
+            hash = 0x80000000;
+
+        return hash;
+    }
+
+    inline unsigned stringHash(const char* data, unsigned length)
+    {
+        unsigned hash = WTF::stringHashingStartValue;
+        unsigned rem = length & 1;
+        length >>= 1;
+
+        // Main loop
+        for (; length > 0; length--) {
+            hash += static_cast<unsigned char>(data[0]);
+            unsigned tmp = (static_cast<unsigned char>(data[1]) << 11) ^ hash;
+            hash = (hash << 16) ^ tmp;
+            data += 2;
+            hash += hash >> 11;
+        }
+
+        // Handle end case
+        if (rem) {
+            hash += static_cast<unsigned char>(data[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
+        if (hash == 0)
+            hash = 0x80000000;
+
+        return hash;
+    }
+
+    inline unsigned stringHash(const char* data)
+    {
+        unsigned hash = WTF::stringHashingStartValue;
+        
+        // Main loop
+        for (;;) {
+            unsigned char b0 = data[0];
+            if (!b0)
+                break;
+            unsigned char b1 = data[1];
+            if (!b1) {
+                hash += b0;
+                hash ^= hash << 11;
+                hash += hash >> 17;
+                break;
+            }
+            hash += b0;
+            unsigned tmp = (b1 << 11) ^ hash;
+            hash = (hash << 16) ^ tmp;
+            data += 2;
+            hash += hash >> 11;
+        }
+        
+        // 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.
+        if (hash == 0)
+            hash = 0x80000000;
+        
+        return hash;
+    }
+
 } // namespace WTF
 
 using WTF::DefaultHash;
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 3a03b73..52f996c 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,13 @@
+2010-01-04  Gavin Barraclough  <barraclough at apple.com>
+
+        Reviewed by Sam Weinig.
+
+        https://bugs.webkit.org/show_bug.cgi?id=33163
+        Use WTF's string hashing functions from StringImpl.
+
+        * platform/text/StringImpl.h:
+        (WebCore::StringImpl::computeHash):
+
 2010-01-04  Simon Fraser  <simon.fraser at apple.com>
 
         Reviewed by Dan Bernstein.
diff --git a/WebCore/platform/text/StringImpl.h b/WebCore/platform/text/StringImpl.h
index b454463..75f1f2f 100644
--- a/WebCore/platform/text/StringImpl.h
+++ b/WebCore/platform/text/StringImpl.h
@@ -26,6 +26,7 @@
 #include <limits.h>
 #include <wtf/ASCIICType.h>
 #include <wtf/CrossThreadRefCounted.h>
+#include <wtf/HashFunctions.h>
 #include <wtf/OwnFastMallocPtr.h>
 #include <wtf/PtrAndFlags.h>
 #include <wtf/RefCounted.h>
@@ -102,8 +103,8 @@ public:
 
     unsigned hash() { if (m_hash == 0) m_hash = computeHash(m_data, m_length); return m_hash; }
     unsigned existingHash() const { ASSERT(m_hash); return m_hash; }
-    static unsigned computeHash(const UChar*, unsigned len);
-    static unsigned computeHash(const char*);
+    inline static unsigned computeHash(const UChar* data, unsigned length) { return WTF::stringHash(data, length); }
+    inline static unsigned computeHash(const char* data) { return WTF::stringHash(data); }
     
     // Returns a StringImpl suitable for use on another thread.
     PassRefPtr<StringImpl> crossThreadString();
@@ -213,91 +214,6 @@ inline bool equalIgnoringCase(const char* a, const UChar* b, unsigned length) {
 
 bool equalIgnoringNullity(StringImpl*, StringImpl*);
 
-// Golden ratio - arbitrary start value to avoid mapping all 0's to all 0's
-// or anything like that.
-const unsigned phi = 0x9e3779b9U;
-
-// Paul Hsieh's SuperFastHash
-// http://www.azillionmonkeys.com/qed/hash.html
-inline unsigned StringImpl::computeHash(const UChar* data, unsigned length)
-{
-    unsigned hash = phi;
-    
-    // Main loop.
-    for (unsigned pairCount = length >> 1; pairCount; pairCount--) {
-        hash += data[0];
-        unsigned tmp = (data[1] << 11) ^ hash;
-        hash = (hash << 16) ^ tmp;
-        data += 2;
-        hash += hash >> 11;
-    }
-    
-    // Handle end case.
-    if (length & 1) {
-        hash += data[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;
-}
-
-// Paul Hsieh's SuperFastHash
-// http://www.azillionmonkeys.com/qed/hash.html
-inline unsigned StringImpl::computeHash(const char* data)
-{
-    // 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 should give matching results
-
-    unsigned hash = phi;
-    
-    // Main loop
-    for (;;) {
-        unsigned char b0 = data[0];
-        if (!b0)
-            break;
-        unsigned char b1 = data[1];
-        if (!b1) {
-            hash += b0;
-            hash ^= hash << 11;
-            hash += hash >> 17;
-            break;
-        }
-        hash += b0;
-        unsigned tmp = (b1 << 11) ^ hash;
-        hash = (hash << 16) ^ tmp;
-        data += 2;
-        hash += hash >> 11;
-    }
-    
-    // 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 inline bool isSpaceOrNewline(UChar c)
 {
     // Use isASCIISpace() for basic Latin-1.

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list