From ffb1fefc9fd1bc26cab365dacf0813bf349c65a7 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 7 Sep 2015 21:15:32 -0700 Subject: [PATCH] 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 | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/xpcom/base/nsCycleCollector.cpp b/xpcom/base/nsCycleCollector.cpp index 029144cab225..4b82712e70c3 100644 --- a/xpcom/base/nsCycleCollector.cpp +++ b/xpcom/base/nsCycleCollector.cpp @@ -868,9 +868,10 @@ public: } #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 { @@ -894,11 +895,17 @@ public: } }; +PtrToNodeEntry* +CCGraph::FindNodeEntry(void* aPtr) +{ + return + static_cast(PL_DHashTableSearch(&mPtrToNodeMap, aPtr)); +} + PtrInfo* CCGraph::FindNode(void* aPtr) { - PtrToNodeEntry* e = - static_cast(PL_DHashTableSearch(&mPtrToNodeMap, aPtr)); + PtrToNodeEntry* e = FindNodeEntry(aPtr); return e ? e->mNode : nullptr; } @@ -921,9 +928,9 @@ CCGraph::AddNodeToMap(void* aPtr) } void -CCGraph::RemoveNodeFromMap(void* aPtr) +CCGraph::RemoveNodeFromMap(PtrToNodeEntry* aEntry) { - PL_DHashTableRemove(&mPtrToNodeMap, aPtr); + mPtrToNodeMap.RemoveEntry(aEntry); } @@ -3838,8 +3845,10 @@ nsCycleCollector::RemoveObjectFromGraph(void* aObj) 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;