Bug 1202526 (part 8) - Use PLDHashTable::RemoveEntry() in the cycle collector. r=mccr8.
authorNicholas Nethercote <nnethercote@mozilla.com>
Mon, 07 Sep 2015 21:15:32 -0700
changeset 294329 2afc1965006352aa4213e02d745e3ac07a2fc5c2
parent 294328 1ff0bf051b2429470dddf879c647abb57ac4a118
child 294330 c1f58ad695a35d486078e30bbb362f999bb26366
push id5245
push userraliiev@mozilla.com
push dateThu, 29 Oct 2015 11:30:51 +0000
treeherdermozilla-beta@dac831dc1bd0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmccr8
bugs1202526
milestone43.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1202526 (part 8) - Use PLDHashTable::RemoveEntry() in the cycle collector. r=mccr8. This avoids repeating the hash table search in order to remove a CC graph entry, which is good because it's a common operation.
xpcom/base/nsCycleCollector.cpp
--- a/xpcom/base/nsCycleCollector.cpp
+++ b/xpcom/base/nsCycleCollector.cpp
@@ -863,19 +863,20 @@ public:
   bool IsEmpty()
   {
     return mNodes.IsEmpty() && mEdges.IsEmpty() &&
            mWeakMaps.IsEmpty() && mRootCount == 0 &&
            mPtrToNodeMap.EntryCount() == 0;
   }
 #endif
 
+  PtrToNodeEntry* FindNodeEntry(void* aPtr);
   PtrInfo* FindNode(void* aPtr);
   PtrToNodeEntry* AddNodeToMap(void* aPtr);
-  void RemoveNodeFromMap(void* aPtr);
+  void RemoveNodeFromMap(PtrToNodeEntry* aPtr);
 
   uint32_t MapCount() const
   {
     return mPtrToNodeMap.EntryCount();
   }
 
   size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const
   {
@@ -889,21 +890,27 @@ public:
     n += mWeakMaps.ShallowSizeOfExcludingThis(aMallocSizeOf);
 
     n += mPtrToNodeMap.ShallowSizeOfExcludingThis(aMallocSizeOf);
 
     return n;
   }
 };
 
+PtrToNodeEntry*
+CCGraph::FindNodeEntry(void* aPtr)
+{
+  return
+    static_cast<PtrToNodeEntry*>(PL_DHashTableSearch(&mPtrToNodeMap, aPtr));
+}
+
 PtrInfo*
 CCGraph::FindNode(void* aPtr)
 {
-  PtrToNodeEntry* e =
-    static_cast<PtrToNodeEntry*>(PL_DHashTableSearch(&mPtrToNodeMap, aPtr));
+  PtrToNodeEntry* e = FindNodeEntry(aPtr);
   return e ? e->mNode : nullptr;
 }
 
 PtrToNodeEntry*
 CCGraph::AddNodeToMap(void* aPtr)
 {
   JS::AutoSuppressGCAnalysis suppress;
   if (mOutOfMemory) {
@@ -916,19 +923,19 @@ CCGraph::AddNodeToMap(void* aPtr)
     mOutOfMemory = true;
     MOZ_ASSERT(false, "Ran out of memory while building cycle collector graph");
     return nullptr;
   }
   return e;
 }
 
 void
-CCGraph::RemoveNodeFromMap(void* aPtr)
+CCGraph::RemoveNodeFromMap(PtrToNodeEntry* aEntry)
 {
-  PL_DHashTableRemove(&mPtrToNodeMap, aPtr);
+  mPtrToNodeMap.RemoveEntry(aEntry);
 }
 
 
 static nsISupports*
 CanonicalizeXPCOMParticipant(nsISupports* aIn)
 {
   nsISupports* out = nullptr;
   aIn->QueryInterface(NS_GET_IID(nsCycleCollectionISupports),
@@ -3833,18 +3840,20 @@ nsCycleCollector::Shutdown()
 
 void
 nsCycleCollector::RemoveObjectFromGraph(void* aObj)
 {
   if (mIncrementalPhase == IdlePhase) {
     return;
   }
 
-  if (PtrInfo* pinfo = mGraph.FindNode(aObj)) {
-    mGraph.RemoveNodeFromMap(aObj);
+  PtrToNodeEntry* e = mGraph.FindNodeEntry(aObj);
+  PtrInfo* pinfo = e ? e->mNode : nullptr;
+  if (pinfo) {
+    mGraph.RemoveNodeFromMap(e);
 
     pinfo->mPointer = nullptr;
     pinfo->mParticipant = nullptr;
   }
 }
 
 void
 nsCycleCollector::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf,