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
--- 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