Bug 1290614, part 5 - Split out the last iteration of the XPCNativeSetKey loops. r=mrbkap
Now I take advantage of knowing that any new interface is always being
added to the end of the set.
Further cleanup of Hash() will happen in the next patch.
MozReview-Commit-ID: EoESTOfIOr
--- a/js/xpconnect/src/XPCMaps.cpp
+++ b/js/xpconnect/src/XPCMaps.cpp
@@ -273,33 +273,27 @@ NativeSetMap::Entry::Match(const PLDHash
SetInTable->GetInterfaceAt(0) == Addition) ||
(SetInTable->GetInterfaceCount() == 2 &&
SetInTable->GetInterfaceAt(1) == Addition);
}
if (!Addition && Set == SetInTable)
return true;
- uint16_t count = Set->GetInterfaceCount() + (Addition ? 1 : 0);
- if (count != SetInTable->GetInterfaceCount())
+ uint16_t count = Set->GetInterfaceCount();
+ if (count + (Addition ? 1 : 0) != SetInTable->GetInterfaceCount())
return false;
XPCNativeInterface** CurrentInTable = SetInTable->GetInterfaceArray();
XPCNativeInterface** Current = Set->GetInterfaceArray();
for (uint16_t i = 0; i < count; i++) {
- if (Addition && i == Set->GetInterfaceCount()) {
- if (Addition != *(CurrentInTable++))
- return false;
- } else {
- if (*(Current++) != *(CurrentInTable++))
- return false;
- }
+ if (*(Current++) != *(CurrentInTable++))
+ return false;
}
-
- return true;
+ return !Addition || Addition == *(CurrentInTable++);
}
const struct PLDHashTableOps NativeSetMap::Entry::sOps =
{
HashNativeKey,
Match,
PLDHashTable::MoveEntryStub,
PLDHashTable::ClearEntryStub
--- a/js/xpconnect/src/XPCWrappedNativeInfo.cpp
+++ b/js/xpconnect/src/XPCWrappedNativeInfo.cpp
@@ -438,23 +438,20 @@ XPCNativeSetKey::Hash() const
if (!mBaseSet) {
MOZ_ASSERT(mAddition, "bad key");
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 == mBaseSet->GetInterfaceCount())
- h ^= HashPointer(mAddition);
- else
- h ^= HashPointer(*(current++));
+ h ^= HashPointer(*(current++));
}
+ h ^= HashPointer(mAddition);
} else {
for (uint16_t i = 0; i < count; i++)
h ^= HashPointer(*(current++));
}
}
return h;
}
@@ -762,19 +759,20 @@ XPCNativeSet::NewInstanceMutate(XPCNativ
XPCNativeSet* obj = new(place) XPCNativeSet();
obj->mMemberCount = otherSet->GetMemberCount() +
newInterface->GetMemberCount();
obj->mInterfaceCount = otherSet->mInterfaceCount + 1;
XPCNativeInterface** src = otherSet->mInterfaces;
XPCNativeInterface** dest = obj->mInterfaces;
- for (uint16_t i = 0; i < obj->mInterfaceCount; i++) {
- NS_ADDREF(*dest++ = (i == otherSet->mInterfaceCount) ? newInterface : *src++);
+ for (uint16_t i = 0; i < otherSet->mInterfaceCount; i++) {
+ NS_ADDREF(*dest++ = *src++);
}
+ NS_ADDREF(*dest++ = newInterface);
return obj;
}
// static
void
XPCNativeSet::DestroyInstance(XPCNativeSet* inst)
{