Bug 1173247 (part 1) - Remove PL_DHashTableEnumerate() uses from nsDiskCacheBindery. r=michal.
authorNicholas Nethercote <nnethercote@mozilla.com>
Wed, 10 Jun 2015 13:07:41 -0700
changeset 279343 2797813b89bc013796edb12216d3c27952b66696
parent 279342 e6a1e112c0aaa88cdb2e88ba5d8574ce60bfa7fd
child 279344 416257a77854f00da2c5938c724f2bbf6f3f6476
push id4932
push userjlund@mozilla.com
push dateMon, 10 Aug 2015 18:23:06 +0000
treeherdermozilla-beta@6dd5a4f5f745 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmichal
bugs1173247
milestone41.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 1173247 (part 1) - Remove PL_DHashTableEnumerate() uses from nsDiskCacheBindery. r=michal.
netwerk/cache/nsDiskCacheBinding.cpp
--- a/netwerk/cache/nsDiskCacheBinding.cpp
+++ b/netwerk/cache/nsDiskCacheBinding.cpp
@@ -357,59 +357,43 @@ nsDiskCacheBindery::ActiveBindings()
     if (!initialized) return false;
 
     bool    activeBinding = false;
     PL_DHashTableEnumerate(&table, ActiveBinding, &activeBinding);
 
     return activeBinding;
 }
 
-struct AccumulatorArg {
-    size_t mUsage;
-    mozilla::MallocSizeOf mMallocSizeOf;
-};
-
-PLDHashOperator
-AccumulateHeapUsage(PLDHashTable *table, PLDHashEntryHdr *hdr, uint32_t number,
-                    void *arg)
-{
-    nsDiskCacheBinding *binding = ((HashTableEntry *)hdr)->mBinding;
-    NS_ASSERTION(binding, "### disk cache binding = nsnull!");
-
-    AccumulatorArg *acc = (AccumulatorArg *)arg;
-
-    nsDiskCacheBinding *head = binding;
-    do {
-        acc->mUsage += acc->mMallocSizeOf(binding);
-
-        if (binding->mStreamIO) {
-            acc->mUsage += binding->mStreamIO->SizeOfIncludingThis(acc->mMallocSizeOf);
-        }
-
-        /* No good way to get at mDeactivateEvent internals for proper size, so
-           we use this as an estimate. */
-        if (binding->mDeactivateEvent) {
-            acc->mUsage += acc->mMallocSizeOf(binding->mDeactivateEvent);
-        }
-
-        binding = (nsDiskCacheBinding *)PR_NEXT_LINK(binding);
-    } while (binding != head);
-
-    return PL_DHASH_NEXT;
-}
-
 /**
- * SizeOfExcludingThis: return the amount of heap memory (bytes) being used by the bindery
+ * SizeOfExcludingThis: return the amount of heap memory (bytes) being used by
+ * the bindery.
  */
 size_t
 nsDiskCacheBindery::SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf)
 {
     NS_ASSERTION(initialized, "nsDiskCacheBindery not initialized");
     if (!initialized) return 0;
 
-    AccumulatorArg arg;
-    arg.mUsage = 0;
-    arg.mMallocSizeOf = aMallocSizeOf;
+    size_t size = 0;
+
+    PLDHashTable::Iterator iter(&table);
+    while (iter.HasMoreEntries()) {
+        auto entry = static_cast<HashTableEntry*>(iter.NextEntry());
+        nsDiskCacheBinding* binding = entry->mBinding;
 
-    PL_DHashTableEnumerate(&table, AccumulateHeapUsage, &arg);
+        nsDiskCacheBinding* head = binding;
+        do {
+            size += aMallocSizeOf(binding);
+            if (binding->mStreamIO) {
+                size += binding->mStreamIO->SizeOfIncludingThis(aMallocSizeOf);
+            }
 
-    return arg.mUsage;
+            // No good way to get at mDeactivateEvent internals for proper
+            // size, so we use this as an estimate.
+            if (binding->mDeactivateEvent) {
+                size += aMallocSizeOf(binding->mDeactivateEvent);
+            }
+            binding = (nsDiskCacheBinding *)PR_NEXT_LINK(binding);
+        } while (binding != head);
+    }
+
+    return size;
 }