Bug 923328 - Ionmonkey: fix float32 hash function. r=terrence
authorDouglas Crosher <dtc-moz@scieneer.com>
Thu, 03 Oct 2013 10:11:18 +1000
changeset 149916 bd7bb523c5dcb9f65e1ecd5faf1333e7983f18bb
parent 149915 c00387255d25ba3567861a5fe1db3825c79bcbd5
child 149935 758fdfc588f6430405cf2fb838dea910e0a87abc
child 149975 99b749ea1fb9238e8dc91a6d0ea46acddc8ccc64
push id25405
push userphilringnalda@gmail.com
push dateSat, 05 Oct 2013 05:04:31 +0000
treeherdermozilla-central@bd7bb523c5dc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersterrence
bugs923328
milestone27.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 923328 - Ionmonkey: fix float32 hash function. r=terrence
js/public/HashTable.h
--- a/js/public/HashTable.h
+++ b/js/public/HashTable.h
@@ -570,16 +570,29 @@ struct DefaultHasher<double>
         uint64_t u = mozilla::BitwiseCast<uint64_t>(d);
         return HashNumber(u ^ (u >> 32));
     }
     static bool match(double lhs, double rhs) {
         return mozilla::BitwiseCast<uint64_t>(lhs) == mozilla::BitwiseCast<uint64_t>(rhs);
     }
 };
 
+template <>
+struct DefaultHasher<float>
+{
+    typedef float Lookup;
+    static HashNumber hash(float f) {
+        JS_STATIC_ASSERT(sizeof(HashNumber) == 4);
+        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);
+    }
+};
+
 /*****************************************************************************/
 
 // 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>