Bug 885175 - DoubleHasher<double> fixes -- use a bitwise comparison to avoid considering zero and negative zero equal. r=luke
authorDan Gohman <sunfish@google.com>
Thu, 20 Jun 2013 11:55:41 -0700
changeset 147354 806a358aa8b2b02389e2d0a5111481ba237aae43
parent 147353 ad548e637ac10a4c9a5eaf0d6945cadb5f514d82
child 147355 f822fe6c9708a2c8aa84f165db65e1d2cddca199
push id2697
push userbbajaj@mozilla.com
push dateMon, 05 Aug 2013 18:49:53 +0000
treeherdermozilla-beta@dfec938c7b63 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersluke
bugs885175
milestone24.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 885175 - DoubleHasher<double> fixes -- use a bitwise comparison to avoid considering zero and negative zero equal. r=luke
js/public/HashTable.h
--- a/js/public/HashTable.h
+++ b/js/public/HashTable.h
@@ -4,16 +4,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef js_HashTable_h
 #define js_HashTable_h
 
 #include "mozilla/Assertions.h"
 #include "mozilla/Attributes.h"
+#include "mozilla/Casting.h"
 #include "mozilla/DebugOnly.h"
 #include "mozilla/PodOperations.h"
 #include "mozilla/TypeTraits.h"
 #include "mozilla/Util.h"
 
 #include "js/TemplateLib.h"
 #include "js/Utility.h"
 
@@ -537,28 +538,21 @@ struct DefaultHasher<T *> : PointerHashe
 
 // For doubles, we can xor the two uint32s.
 template <>
 struct DefaultHasher<double>
 {
     typedef double Lookup;
     static HashNumber hash(double d) {
         JS_STATIC_ASSERT(sizeof(HashNumber) == 4);
-        union {
-            struct {
-                uint32_t lo;
-                uint32_t hi;
-            } s;
-            double d;
-        } u;
-        u.d = d;
-        return u.s.lo ^ u.s.hi;
+        uint64_t u = mozilla::BitwiseCast<uint64_t>(d);
+        return HashNumber(u ^ (u >> 32));
     }
     static bool match(double lhs, double rhs) {
-        return lhs == rhs;
+        return mozilla::BitwiseCast<uint64_t>(lhs) == mozilla::BitwiseCast<uint64_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