Bug 1290587, part 5 - Add helper function to hash pointers in HashNativeKey. r=mrbkap draft
authorAndrew McCreight <continuation@gmail.com>
Fri, 29 Jul 2016 10:46:54 -0700
changeset 394787 db5ef32b7631527617e3cc391cb7a6ceccb9f019
parent 394786 8a768f235f306b4711579aa983ce01759b08acfc
child 394788 b861ff46d7542964fb8dd559994d3420665fafd0
push id24631
push userbmo:continuation@gmail.com
push dateSun, 31 Jul 2016 18:47:25 +0000
reviewersmrbkap
bugs1290587
milestone50.0a1
Bug 1290587, part 5 - Add helper function to hash pointers in HashNativeKey. r=mrbkap Also, use NS_PTR_TO_UINT32 instead of NS_PTR_TO_INT32 because it is not undefined. Get rid of the optimization of 0 ^ x which required a comment. MozReview-Commit-ID: HPz5VgRnLN1
js/xpconnect/src/XPCWrappedNativeInfo.cpp
--- a/js/xpconnect/src/XPCWrappedNativeInfo.cpp
+++ b/js/xpconnect/src/XPCWrappedNativeInfo.cpp
@@ -421,40 +421,44 @@ XPCNativeInterface::DebugDump(int16_t de
         XPC_LOG_ALWAYS(("mInfo @ %x", mInfo.get()));
         XPC_LOG_OUTDENT();
 #endif
 }
 
 /***************************************************************************/
 // XPCNativeSetKey
 
+static PLDHashNumber
+HashPointer(const void* ptr)
+{
+    return NS_PTR_TO_UINT32(ptr) >> 2;
+}
+
 PLDHashNumber
 XPCNativeSetKey::Hash() const
 {
     PLDHashNumber h = 0;
 
     if (!mBaseSet) {
         MOZ_ASSERT(mAddition, "bad key");
-        // This would be an XOR like below.
-        // But "0 ^ x == x". So it does not matter.
-        h = (js::HashNumber) NS_PTR_TO_INT32(mAddition) >> 2;
+        h ^= HashPointer(mAddition);
     } else {
         XPCNativeInterface** current = mBaseSet->GetInterfaceArray();
         uint16_t count = mBaseSet->GetInterfaceCount();
         if (mAddition) {
             count++;
             for (uint16_t i = 0; i < count; i++) {
                 if (i == mPosition)
-                    h ^= (js::HashNumber) NS_PTR_TO_INT32(mAddition) >> 2;
+                    h ^= HashPointer(mAddition);
                 else
-                    h ^= (js::HashNumber) NS_PTR_TO_INT32(*(current++)) >> 2;
+                    h ^= HashPointer(*(current++));
             }
         } else {
             for (uint16_t i = 0; i < count; i++)
-                h ^= (js::HashNumber) NS_PTR_TO_INT32(*(current++)) >> 2;
+                h ^= HashPointer(*(current++));
         }
     }
 
     return h;
 }
 
 /***************************************************************************/
 // XPCNativeSet