Bug 899834 (attempt 2) - Use a better hash function for the atoms table. r=luke.
authorNicholas Nethercote <nnethercote@mozilla.com>
Tue, 30 Jul 2013 18:01:26 -0700
changeset 153272 e106a8c9ac8c06ec77692750377ea64568d0853e
parent 153271 938037f239b16ee371515058a3d3aea6ede52eb5
child 153273 82adb6106f7aa0259220750adceec190de5d008b
push id2859
push userakeybl@mozilla.com
push dateMon, 16 Sep 2013 19:14:59 +0000
treeherdermozilla-beta@87d3c51cd2bf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersluke
bugs899834
milestone25.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 899834 (attempt 2) - Use a better hash function for the atoms table. r=luke.
js/src/jsatom.h
--- a/js/src/jsatom.h
+++ b/js/src/jsatom.h
@@ -48,26 +48,16 @@ struct JsidHasher
 
 /*
  * Return a printable, lossless char[] representation of a string-type atom.
  * The lifetime of the result matches the lifetime of bytes.
  */
 extern const char *
 AtomToPrintableString(ExclusiveContext *cx, JSAtom *atom, JSAutoByteString *bytes);
 
-/* Compute a hash function from chars/length. */
-inline uint32_t
-HashChars(const jschar *chars, size_t length)
-{
-    uint32_t h = 0;
-    for (; length; chars++, length--)
-        h = JS_ROTATE_LEFT32(h, 4) ^ *chars;
-    return h;
-}
-
 class AtomStateEntry
 {
     uintptr_t bits;
 
     static const uintptr_t NO_TAG_MASK = uintptr_t(-1) - 1;
 
   public:
     AtomStateEntry() : bits(0) {}
@@ -100,17 +90,17 @@ struct AtomHasher
         const jschar    *chars;
         size_t          length;
         const JSAtom    *atom; /* Optional. */
 
         Lookup(const jschar *chars, size_t length) : chars(chars), length(length), atom(NULL) {}
         inline Lookup(const JSAtom *atom);
     };
 
-    static HashNumber hash(const Lookup &l) { return HashChars(l.chars, l.length); }
+    static HashNumber hash(const Lookup &l) { return mozilla::HashString(l.chars, l.length); }
     static inline bool match(const AtomStateEntry &entry, const Lookup &lookup);
 };
 
 typedef HashSet<AtomStateEntry, AtomHasher, SystemAllocPolicy> AtomSet;
 
 class PropertyName;
 
 }  /* namespace js */