Bug 1186792 - Replace nsBaseHashtable::EnumerateRead() calls in hal/ with iterators. r=dhylands.
authorNicholas Nethercote <nnethercote@mozilla.com>
Mon, 19 Oct 2015 21:35:20 -0700
changeset 302643 4ee3dd50843ae3fb5bb849abacc7dfc46b6139b4
parent 302642 6e8eb48dac54ff18d6ed83f970579d0914c46bfc
child 302644 7f2acbbadd117438960fa1176ef5c067571372a3
push id6653
push userbcampen@mozilla.com
push dateThu, 22 Oct 2015 13:28:47 +0000
reviewersdhylands
bugs1186792
milestone44.0a1
Bug 1186792 - Replace nsBaseHashtable::EnumerateRead() calls in hal/ with iterators. r=dhylands.
hal/HalWakeLock.cpp
--- a/hal/HalWakeLock.cpp
+++ b/hal/HalWakeLock.cpp
@@ -1,9 +1,10 @@
-/* -*- Mode: C++; tab-width: 40; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "Hal.h"
 #include "mozilla/HalWakeLock.h"
 #include "mozilla/Services.h"
 #include "mozilla/StaticPtr.h"
@@ -49,46 +50,46 @@ WakeLockInfoFromLockCount(const nsAStrin
   WakeLockInformation info;
   info.topic() = aTopic;
   info.numLocks() = aLockCount.numLocks;
   info.numHidden() = aLockCount.numHidden;
   info.lockingProcesses().AppendElements(aLockCount.processes);
   return info;
 }
 
-PLDHashOperator
-CountWakeLocks(const uint64_t& aKey, LockCount aCount, void* aUserArg)
+static void
+CountWakeLocks(ProcessLockTable* aTable, LockCount* aTotalCount)
 {
-  MOZ_ASSERT(aUserArg);
+  for (auto iter = aTable->Iter(); !iter.Done(); iter.Next()) {
+    const uint64_t& key = iter.Key();
+    LockCount count = iter.UserData();
 
-  LockCount* totalCount = static_cast<LockCount*>(aUserArg);
-  totalCount->numLocks += aCount.numLocks;
-  totalCount->numHidden += aCount.numHidden;
+    aTotalCount->numLocks += count.numLocks;
+    aTotalCount->numHidden += count.numHidden;
 
-  // This is linear in the number of processes, but that should be small.
-  if (!totalCount->processes.Contains(aKey)) {
-    totalCount->processes.AppendElement(aKey);
+    // This is linear in the number of processes, but that should be small.
+    if (!aTotalCount->processes.Contains(key)) {
+      aTotalCount->processes.AppendElement(key);
+    }
   }
-
-  return PL_DHASH_NEXT;
 }
 
 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;
-    aTable->EnumerateRead(CountWakeLocks, &totalCount);
+    CountWakeLocks(aTable, &totalCount);
     if (!totalCount.numLocks) {
       op = PL_DHASH_REMOVE;
     }
 
     if (sActiveListeners) {
       NotifyWakeLockChange(WakeLockInfoFromLockCount(aKey, totalCount));
     }
   }
@@ -217,17 +218,17 @@ ModifyWakeLock(const nsAString& aTopic,
   ProcessLockTable* table = sLockTable->Get(aTopic);
   LockCount processCount;
   LockCount totalCount;
   if (!table) {
     table = new ProcessLockTable();
     sLockTable->Put(aTopic, table);
   } else {
     table->Get(aProcessID, &processCount);
-    table->EnumerateRead(CountWakeLocks, &totalCount);
+    CountWakeLocks(table, &totalCount);
   }
 
   MOZ_ASSERT(processCount.numLocks >= processCount.numHidden);
   MOZ_ASSERT(aLockAdjust >= 0 || processCount.numLocks > 0);
   MOZ_ASSERT(aHiddenAdjust >= 0 || processCount.numHidden > 0);
   MOZ_ASSERT(totalCount.numLocks >= totalCount.numHidden);
   MOZ_ASSERT(aLockAdjust >= 0 || totalCount.numLocks > 0);
   MOZ_ASSERT(aHiddenAdjust >= 0 || totalCount.numHidden > 0);
@@ -274,14 +275,14 @@ GetWakeLockInfo(const nsAString& aTopic,
   }
 
   ProcessLockTable* table = sLockTable->Get(aTopic);
   if (!table) {
     *aWakeLockInfo = WakeLockInfoFromLockCount(aTopic, LockCount());
     return;
   }
   LockCount totalCount;
-  table->EnumerateRead(CountWakeLocks, &totalCount);
+  CountWakeLocks(table, &totalCount);
   *aWakeLockInfo = WakeLockInfoFromLockCount(aTopic, totalCount);
 }
 
 } // namespace hal_impl
 } // namespace mozilla