Bug 1290614, part 4 - Stop storing mPosition in XPCNativeSetKey. r=mrbkap draft
authorAndrew McCreight <continuation@gmail.com>
Sun, 31 Jul 2016 13:50:11 -0700
changeset 405483 1b6fd894da82cb1e47d82c77719ad9bb070b386c
parent 405482 98baf421124a650adffce94e6278924c672a57fc
child 405484 e632153bb8b9e143ad269e1146465b91d4ea5ed9
push id27502
push userbmo:continuation@gmail.com
push dateThu, 25 Aug 2016 14:52:41 +0000
reviewersmrbkap
bugs1290614
milestone51.0a1
Bug 1290614, part 4 - Stop storing mPosition in XPCNativeSetKey. r=mrbkap There are three cases for a key, represented by the three ctors: 1. mBaseSet is non-null, mAddition is null. 2. mBaseSet is null, mAddition is non-null. 3. Both mBaseSet and mAddition are non-null. In the three places that use the value of mPosition, condition 3 holds, so the key must have been constructed using the third ctor. For this ctor, mPosition is equal to mBaseSet->GetInterfaceCount(), so I substitute the value and eliminate the field. This makes a check in NewInstanceMutate() trivially false, so I eliminated that, too. MozReview-Commit-ID: 1SOF6GyccU7
js/xpconnect/src/XPCInlines.h
js/xpconnect/src/XPCMaps.cpp
js/xpconnect/src/XPCWrappedNativeInfo.cpp
js/xpconnect/src/xpcprivate.h
--- a/js/xpconnect/src/XPCInlines.h
+++ b/js/xpconnect/src/XPCInlines.h
@@ -278,17 +278,16 @@ XPCNativeInterface::OffsetOfMembers()
 }
 
 /***************************************************************************/
 
 inline XPCNativeSetKey::XPCNativeSetKey(XPCNativeSet* baseSet,
                                         XPCNativeInterface* addition)
     : mBaseSet(baseSet)
     , mAddition(addition)
-    , mPosition(baseSet->GetInterfaceCount())
 {
     MOZ_ASSERT(mBaseSet);
     MOZ_ASSERT(mAddition);
     MOZ_ASSERT(!mBaseSet->HasInterface(mAddition));
 }
 
 /***************************************************************************/
 
--- a/js/xpconnect/src/XPCMaps.cpp
+++ b/js/xpconnect/src/XPCMaps.cpp
@@ -277,21 +277,20 @@ NativeSetMap::Entry::Match(const PLDHash
 
     if (!Addition && Set == SetInTable)
         return true;
 
     uint16_t count = Set->GetInterfaceCount() + (Addition ? 1 : 0);
     if (count != SetInTable->GetInterfaceCount())
         return false;
 
-    uint16_t Position = Key->GetPosition();
     XPCNativeInterface** CurrentInTable = SetInTable->GetInterfaceArray();
     XPCNativeInterface** Current = Set->GetInterfaceArray();
     for (uint16_t i = 0; i < count; i++) {
-        if (Addition && i == Position) {
+        if (Addition && i == Set->GetInterfaceCount()) {
             if (Addition != *(CurrentInTable++))
                 return false;
         } else {
             if (*(Current++) != *(CurrentInTable++))
                 return false;
         }
     }
 
--- a/js/xpconnect/src/XPCWrappedNativeInfo.cpp
+++ b/js/xpconnect/src/XPCWrappedNativeInfo.cpp
@@ -440,17 +440,17 @@ XPCNativeSetKey::Hash() const
         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 == mPosition)
+                if (i == mBaseSet->GetInterfaceCount())
                     h ^= HashPointer(mAddition);
                 else
                     h ^= HashPointer(*(current++));
             }
         } else {
             for (uint16_t i = 0; i < count; i++)
                 h ^= HashPointer(*(current++));
         }
@@ -743,40 +743,37 @@ XPCNativeSet::NewInstance(nsTArray<RefPt
 }
 
 // static
 XPCNativeSet*
 XPCNativeSet::NewInstanceMutate(XPCNativeSetKey* key)
 {
     XPCNativeSet* otherSet = key->GetBaseSet();
     XPCNativeInterface* newInterface = key->GetAddition();
-    uint16_t position = key->GetPosition();
 
     MOZ_ASSERT(otherSet);
 
     if (!newInterface)
         return nullptr;
-    if (position > otherSet->mInterfaceCount)
-        return nullptr;
 
     // Use placement new to create an object with the right amount of space
     // to hold the members array
     int size = sizeof(XPCNativeSet);
     size += otherSet->mInterfaceCount * sizeof(XPCNativeInterface*);
     void* place = new char[size];
     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 == position) ? newInterface : *src++);
+        NS_ADDREF(*dest++ = (i == otherSet->mInterfaceCount) ? newInterface : *src++);
     }
 
     return obj;
 }
 
 // static
 void
 XPCNativeSet::DestroyInstance(XPCNativeSet* inst)
--- a/js/xpconnect/src/xpcprivate.h
+++ b/js/xpconnect/src/xpcprivate.h
@@ -1272,48 +1272,46 @@ private:
 // It represents a new XPCNativeSet we are considering constructing, without
 // requiring that the set actually be built.
 
 class XPCNativeSetKey final
 {
 public:
     // This represents an existing set |baseSet|.
     explicit XPCNativeSetKey(XPCNativeSet* baseSet)
-        : mBaseSet(baseSet), mAddition(nullptr), mPosition(0)
+        : mBaseSet(baseSet), mAddition(nullptr)
     {
         MOZ_ASSERT(baseSet);
     }
 
     // This represents a new set containing only nsISupports and
     // |addition|.
     explicit XPCNativeSetKey(XPCNativeInterface* addition)
-        : mBaseSet(nullptr), mAddition(addition), mPosition(0)
+        : mBaseSet(nullptr), mAddition(addition)
     {
         MOZ_ASSERT(addition);
     }
 
     // This represents the existing set |baseSet| with the interface
     // |addition| inserted after existing interfaces. |addition| must
     // not already be present in |baseSet|.
     explicit XPCNativeSetKey(XPCNativeSet* baseSet,
                              XPCNativeInterface* addition);
     ~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;
 };
 
 /***************************************************************************/
 // XPCNativeSet represents an ordered collection of XPCNativeInterface pointers.
 
 class XPCNativeSet final
 {
   public: