Bug 1187142 - Replace nsBaseHashtable::Enumerate() calls in hal/ with iterators. r=dhylands.
authorNicholas Nethercote <nnethercote@mozilla.com>
Mon, 19 Oct 2015 21:52:44 -0700
changeset 268906 7f2acbbadd117438960fa1176ef5c067571372a3
parent 268905 4ee3dd50843ae3fb5bb849abacc7dfc46b6139b4
child 268907 44904f46bc865b5a6272842e520252171ea4e404
push id29566
push usercbook@mozilla.com
push dateThu, 22 Oct 2015 09:45:32 +0000
treeherdermozilla-central@76bd0c01d72e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdhylands
bugs1187142
milestone44.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 1187142 - Replace nsBaseHashtable::Enumerate() calls in hal/ with iterators. r=dhylands.
hal/HalWakeLock.cpp
--- a/hal/HalWakeLock.cpp
+++ b/hal/HalWakeLock.cpp
@@ -67,41 +67,16 @@ CountWakeLocks(ProcessLockTable* aTable,
 
     // This is linear in the number of processes, but that should be small.
     if (!aTotalCount->processes.Contains(key)) {
       aTotalCount->processes.AppendElement(key);
     }
   }
 }
 
-static PLDHashOperator
-RemoveChildFromList(const nsAString& aKey, nsAutoPtr<ProcessLockTable>& aTable,
-                    void* aUserArg)
-{
-  MOZ_ASSERT(aUserArg);
-
-  PLDHashOperator op = PL_DHASH_NEXT;
-  uint64_t childID = *static_cast<uint64_t*>(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:
   NS_DECL_ISUPPORTS
   NS_DECL_NSIOBSERVER
 };
 
 NS_IMPL_ISUPPORTS(ClearHashtableOnShutdown, nsIObserver)
@@ -140,17 +115,35 @@ CleanupOnContentShutdown::Observe(nsISup
     NS_WARNING("ipc:content-shutdown message without property bag as subject");
     return NS_OK;
   }
 
   uint64_t childID = 0;
   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<ProcessLockTable>& 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");
   }
   return NS_OK;
 }
 
 void
 Init()