Bug 1290587, part 2 - Make XPCNativeSetKey hashing a method. r=mrbkap
MozReview-Commit-ID: 67XbmFN4ThW
--- a/js/xpconnect/src/XPCMaps.cpp
+++ b/js/xpconnect/src/XPCMaps.cpp
@@ -29,49 +29,19 @@ HashIIDPtrKey(const void* key)
static bool
MatchIIDPtrKey(const PLDHashEntryHdr* entry, const void* key)
{
return ((const nsID*)key)->
Equals(*((const nsID*)((PLDHashEntryStub*)entry)->key));
}
static PLDHashNumber
-HashNativeKey(const void* key)
+HashNativeKey(const void* data)
{
- auto Key = static_cast<const XPCNativeSetKey*>(key);
-
- PLDHashNumber h = 0;
-
- XPCNativeSet* Set = Key->GetBaseSet();
- XPCNativeInterface* Addition = Key->GetAddition();
- uint16_t Position = Key->GetPosition();
-
- if (!Set) {
- MOZ_ASSERT(Addition, "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(Addition) >> 2;
- } else {
- XPCNativeInterface** Current = Set->GetInterfaceArray();
- uint16_t count = Set->GetInterfaceCount();
- if (Addition) {
- count++;
- for (uint16_t i = 0; i < count; i++) {
- if (i == Position)
- h ^= (js::HashNumber) NS_PTR_TO_INT32(Addition) >> 2;
- else
- h ^= (js::HashNumber) NS_PTR_TO_INT32(*(Current++)) >> 2;
- }
- } else {
- for (uint16_t i = 0; i < count; i++)
- h ^= (js::HashNumber) NS_PTR_TO_INT32(*(Current++)) >> 2;
- }
- }
-
- return h;
+ return static_cast<const XPCNativeSetKey*>(data)->Hash();
}
/***************************************************************************/
// implement JSObject2WrappedJSMap...
void
JSObject2WrappedJSMap::UpdateWeakPointersAfterGC(XPCJSRuntime* runtime)
{
--- a/js/xpconnect/src/XPCWrappedNativeInfo.cpp
+++ b/js/xpconnect/src/XPCWrappedNativeInfo.cpp
@@ -419,16 +419,53 @@ XPCNativeInterface::DebugDump(int16_t de
XPC_LOG_ALWAYS(("name is %s", GetNameString()));
XPC_LOG_ALWAYS(("mMemberCount is %d", mMemberCount));
XPC_LOG_ALWAYS(("mInfo @ %x", mInfo.get()));
XPC_LOG_OUTDENT();
#endif
}
/***************************************************************************/
+// XPCNativeSetKey
+
+PLDHashNumber
+XPCNativeSetKey::Hash() const
+{
+ PLDHashNumber h = 0;
+
+ XPCNativeSet* Set = GetBaseSet();
+ XPCNativeInterface* Addition = GetAddition();
+ uint16_t Position = GetPosition();
+
+ if (!Set) {
+ MOZ_ASSERT(Addition, "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(Addition) >> 2;
+ } else {
+ XPCNativeInterface** Current = Set->GetInterfaceArray();
+ uint16_t count = Set->GetInterfaceCount();
+ if (Addition) {
+ count++;
+ for (uint16_t i = 0; i < count; i++) {
+ if (i == Position)
+ h ^= (js::HashNumber) NS_PTR_TO_INT32(Addition) >> 2;
+ else
+ h ^= (js::HashNumber) NS_PTR_TO_INT32(*(Current++)) >> 2;
+ }
+ } else {
+ for (uint16_t i = 0; i < count; i++)
+ h ^= (js::HashNumber) NS_PTR_TO_INT32(*(Current++)) >> 2;
+ }
+ }
+
+ return h;
+}
+
+/***************************************************************************/
// XPCNativeSet
// static
XPCNativeSet*
XPCNativeSet::GetNewOrUsed(const nsIID* iid)
{
AutoJSContext cx;
AutoMarkingNativeSetPtr set(cx);
--- a/js/xpconnect/src/xpcprivate.h
+++ b/js/xpconnect/src/xpcprivate.h
@@ -1296,16 +1296,18 @@ public:
uint16_t position = 0)
: mBaseSet(baseSet), mAddition(addition), mPosition(position) {}
~XPCNativeSetKey() {}
XPCNativeSet* GetBaseSet() const {return mBaseSet;}
XPCNativeInterface* GetAddition() const {return mAddition;}
uint16_t GetPosition() const {return mPosition;}
+ PLDHashNumber Hash() const;
+
// Allow shallow copy
private:
XPCNativeSet* mBaseSet;
XPCNativeInterface* mAddition;
uint16_t mPosition;
};