Bug 1234985 - Hoist CStringHasher (r=sfink)
--- 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