Bug 1234985 - Hoist CStringHasher (r=sfink)
authorLuke Wagner <luke@mozilla.com>
Wed, 20 Jan 2016 12:00:21 -0600
changeset 303031 a4d3504abe124b5c42daeb1b5d268e2a6a5cc4c1
parent 303030 c34410da6b0130bc5430d18a20ad0357114ab0ed
child 303032 ababaae69ec618ed9740dd898c65be77cb37b8db
push id8978
push userraliiev@mozilla.com
push dateMon, 25 Jan 2016 14:05:32 +0000
treeherdermozilla-aurora@b9a803752a2c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssfink
bugs1234985
milestone46.0a1
Bug 1234985 - Hoist CStringHasher (r=sfink)
js/public/HashTable.h
js/src/vm/UbiNodeCensus.cpp
--- a/js/public/HashTable.h
+++ b/js/public/HashTable.h
@@ -6,16 +6,17 @@
 
 #ifndef js_HashTable_h
 #define js_HashTable_h
 
 #include "mozilla/Alignment.h"
 #include "mozilla/Assertions.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/Casting.h"
+#include "mozilla/HashFunctions.h"
 #include "mozilla/MemoryReporting.h"
 #include "mozilla/Move.h"
 #include "mozilla/PodOperations.h"
 #include "mozilla/ReentrancyGuard.h"
 #include "mozilla/TemplateLib.h"
 #include "mozilla/TypeTraits.h"
 #include "mozilla/UniquePtr.h"
 
@@ -650,16 +651,28 @@ struct DefaultHasher<float>
                       "subsequent code assumes a four-byte hash");
         return HashNumber(mozilla::BitwiseCast<uint32_t>(f));
     }
     static bool match(float lhs, float rhs) {
         return mozilla::BitwiseCast<uint32_t>(lhs) == mozilla::BitwiseCast<uint32_t>(rhs);
     }
 };
 
+// A hash policy that compares C strings.
+struct CStringHasher
+{
+    typedef const char* Lookup;
+    static js::HashNumber hash(Lookup l) {
+        return mozilla::HashString(l);
+    }
+    static bool match(const char* key, Lookup lookup) {
+        return strcmp(key, lookup) == 0;
+    }
+};
+
 /*****************************************************************************/
 
 // Both HashMap and HashSet are implemented by a single HashTable that is even
 // more heavily parameterized than the other two. This leaves HashTable gnarly
 // and extremely coupled to HashMap and HashSet; thus code should not use
 // HashTable directly.
 
 template <class Key, class Value>
--- a/js/src/vm/UbiNodeCensus.cpp
+++ b/js/src/vm/UbiNodeCensus.cpp
@@ -272,27 +272,18 @@ static int compareEntries(const void* lh
     // don't want to just subtract the counts, as they're unsigned.
     if (lhs < rhs)
         return 1;
     if (lhs > rhs)
         return -1;
     return 0;
 }
 
-// A hash policy that compares C strings.
-struct CStringHashPolicy {
-    using Lookup = const char*;
-    static js::HashNumber hash(Lookup l) { return mozilla::HashString(l); }
-    static bool match(const char* key, Lookup lookup) {
-        return strcmp(key, lookup) == 0;
-    }
-};
-
 // A hash map mapping from C strings to counts.
-using CStringCountMap = HashMap<const char*, CountBasePtr, CStringHashPolicy, SystemAllocPolicy>;
+using CStringCountMap = HashMap<const char*, CountBasePtr, CStringHasher, SystemAllocPolicy>;
 
 // Convert a CStringCountMap into an object with each key one of the c strings
 // from the map and each value the associated count's report. For use with
 // reporting.
 static PlainObject*
 cStringCountMapToObject(JSContext* cx, CStringCountMap& map) {
     // Build a vector of pointers to entries; sort by total; and then use
     // that to build the result object. This makes the ordering of entries