From 70347ce8c58bc84751389c71645ce2f51e171630 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 9 Jul 2015 16:54:59 -0700 Subject: [PATCH] Bug 1181445 (part 10) - Use nsBaseHashTable::Iterator in CycleCollectedJSRuntime. r=mccr8. --HG-- extra : rebase_source : 04841562dbe03e48b37c941b540ade0c493ba4e6 --- xpcom/base/CycleCollectedJSRuntime.cpp | 101 ++++++++++--------------- 1 file changed, 40 insertions(+), 61 deletions(-) diff --git a/xpcom/base/CycleCollectedJSRuntime.cpp b/xpcom/base/CycleCollectedJSRuntime.cpp index 8df331ff987f..8656a1d5ac8f 100644 --- a/xpcom/base/CycleCollectedJSRuntime.cpp +++ b/xpcom/base/CycleCollectedJSRuntime.cpp @@ -103,11 +103,6 @@ class IncrementalFinalizeRunnable : public nsRunnable static const PRTime SliceMillis = 5; /* ms */ - static PLDHashOperator - DeferredFinalizerEnumerator(DeferredFinalizeFunction& aFunction, - void*& aData, - void* aClosure); - public: IncrementalFinalizeRunnable(CycleCollectedJSRuntime* aRt, DeferredFinalizerTable& aFinalizerTable); @@ -297,29 +292,6 @@ CheckParticipatesInCycleCollection(JS::GCCellPtr aThing, const char* aName, } } -static PLDHashOperator -NoteJSHolder(void* aHolder, nsScriptObjectTracer*& aTracer, void* aArg) -{ - Closure* closure = static_cast(aArg); - - bool noteRoot; - if (MOZ_UNLIKELY(closure->mCb->WantAllTraces())) { - noteRoot = true; - } else { - closure->mCycleCollectionEnabled = false; - aTracer->Trace(aHolder, - TraceCallbackFunc(CheckParticipatesInCycleCollection), - closure); - noteRoot = closure->mCycleCollectionEnabled; - } - - if (noteRoot) { - closure->mCb->NoteNativeRoot(aHolder, aTracer); - } - - return PL_DHASH_NEXT; -} - NS_IMETHODIMP JSGCThingParticipant::Traverse(void* aPtr, nsCycleCollectionTraversalCallback& aCb) @@ -501,17 +473,14 @@ CycleCollectedJSRuntime::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const return n; } -static PLDHashOperator -UnmarkJSHolder(void* aHolder, nsScriptObjectTracer*& aTracer, void* aArg) -{ - aTracer->CanSkip(aHolder, true); - return PL_DHASH_NEXT; -} - void CycleCollectedJSRuntime::UnmarkSkippableJSHolders() { - mJSHolders.Enumerate(UnmarkJSHolder, nullptr); + for (auto iter = mJSHolders.Iter(); !iter.Done(); iter.Next()) { + void* holder = iter.GetKey(); + nsScriptObjectTracer*& tracer = iter.GetData(); + tracer->CanSkip(holder, true); + } } void @@ -690,7 +659,25 @@ CycleCollectedJSRuntime::TraverseNativeRoots(nsCycleCollectionNoteRootCallback& TraverseAdditionalNativeRoots(aCb); Closure closure(&aCb); - mJSHolders.Enumerate(NoteJSHolder, &closure); + for (auto iter = mJSHolders.Iter(); !iter.Done(); iter.Next()) { + void* holder = iter.GetKey(); + nsScriptObjectTracer*& tracer = iter.GetData(); + + bool noteRoot; + if (MOZ_UNLIKELY(closure.mCb->WantAllTraces())) { + noteRoot = true; + } else { + closure.mCycleCollectionEnabled = false; + tracer->Trace(holder, + TraceCallbackFunc(CheckParticipatesInCycleCollection), + &closure); + noteRoot = closure.mCycleCollectionEnabled; + } + + if (noteRoot) { + closure.mCb->NoteNativeRoot(holder, tracer); + } + } } /* static */ void @@ -813,14 +800,6 @@ struct JsGcTracer : public TraceCallbacks } }; -static PLDHashOperator -TraceJSHolder(void* aHolder, nsScriptObjectTracer*& aTracer, void* aArg) -{ - aTracer->Trace(aHolder, JsGcTracer(), aArg); - - return PL_DHASH_NEXT; -} - void mozilla::TraceScriptHolder(nsISupports* aHolder, JSTracer* aTracer) { @@ -836,7 +815,11 @@ CycleCollectedJSRuntime::TraceNativeGrayRoots(JSTracer* aTracer) // would hurt to do this after the JS holders. TraceAdditionalNativeGrayRoots(aTracer); - mJSHolders.Enumerate(TraceJSHolder, aTracer); + for (auto iter = mJSHolders.Iter(); !iter.Done(); iter.Next()) { + void* holder = iter.GetKey(); + nsScriptObjectTracer*& tracer = iter.GetData(); + tracer->Trace(holder, JsGcTracer(), aTracer); + } } void @@ -1047,27 +1030,23 @@ CycleCollectedJSRuntime::DumpJSHeap(FILE* aFile) } -/* static */ PLDHashOperator -IncrementalFinalizeRunnable::DeferredFinalizerEnumerator(DeferredFinalizeFunction& aFunction, - void*& aData, - void* aClosure) -{ - DeferredFinalizeArray* array = static_cast(aClosure); - - DeferredFinalizeFunctionHolder* function = array->AppendElement(); - function->run = aFunction; - function->data = aData; - - return PL_DHASH_REMOVE; -} - IncrementalFinalizeRunnable::IncrementalFinalizeRunnable(CycleCollectedJSRuntime* aRt, DeferredFinalizerTable& aFinalizers) : mRuntime(aRt) , mFinalizeFunctionToRun(0) , mReleasing(false) { - aFinalizers.Enumerate(DeferredFinalizerEnumerator, &mDeferredFinalizeFunctions); + for (auto iter = aFinalizers.Iter(); !iter.Done(); iter.Next()) { + DeferredFinalizeFunction& function = iter.GetKey(); + void*& data = iter.GetData(); + + DeferredFinalizeFunctionHolder* holder = + mDeferredFinalizeFunctions.AppendElement(); + holder->run = function; + holder->data = data; + + iter.Remove(); + } } IncrementalFinalizeRunnable::~IncrementalFinalizeRunnable()