From 3be952558dca42a23cccbcb9f5312040234c7798 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 19 Oct 2015 21:52:44 -0700 Subject: [PATCH] Bug 1187142 - Replace nsBaseHashtable::Enumerate() calls in hal/ with iterators. r=dhylands. --- hal/HalWakeLock.cpp | 45 +++++++++++++++++++-------------------------- 1 file changed, 19 insertions(+), 26 deletions(-) diff --git a/hal/HalWakeLock.cpp b/hal/HalWakeLock.cpp index 2432ce2387a..a4838bcf367 100644 --- a/hal/HalWakeLock.cpp +++ b/hal/HalWakeLock.cpp @@ -72,31 +72,6 @@ CountWakeLocks(ProcessLockTable* aTable, LockCount* aTotalCount) } } -static PLDHashOperator -RemoveChildFromList(const nsAString& aKey, nsAutoPtr& aTable, - void* aUserArg) -{ - MOZ_ASSERT(aUserArg); - - PLDHashOperator op = PL_DHASH_NEXT; - uint64_t childID = *static_cast(aUserArg); - if (aTable->Get(childID, nullptr)) { - aTable->Remove(childID); - - LockCount totalCount; - CountWakeLocks(aTable, &totalCount); - if (!totalCount.numLocks) { - op = PL_DHASH_REMOVE; - } - - if (sActiveListeners) { - NotifyWakeLockChange(WakeLockInfoFromLockCount(aKey, totalCount)); - } - } - - return op; -} - class ClearHashtableOnShutdown final : public nsIObserver { ~ClearHashtableOnShutdown() {} public: @@ -145,7 +120,25 @@ CleanupOnContentShutdown::Observe(nsISupports* aSubject, const char* aTopic, con nsresult rv = props->GetPropertyAsUint64(NS_LITERAL_STRING("childID"), &childID); if (NS_SUCCEEDED(rv)) { - sLockTable->Enumerate(RemoveChildFromList, &childID); + for (auto iter = sLockTable->Iter(); !iter.Done(); iter.Next()) { + nsAutoPtr& table = iter.Data(); + + if (table->Get(childID, nullptr)) { + table->Remove(childID); + + LockCount totalCount; + CountWakeLocks(table, &totalCount); + + if (sActiveListeners) { + NotifyWakeLockChange(WakeLockInfoFromLockCount(iter.Key(), + totalCount)); + } + + if (totalCount.numLocks == 0) { + iter.Remove(); + } + } + } } else { NS_WARNING("ipc:content-shutdown message without childID property"); }