Bug 1186783 (part 3) - Replace nsBaseHashtable::EnumerateRead() calls in netwerk/ with iterators. r=valentin.
authorNicholas Nethercote <nnethercote@mozilla.com>
Thu, 19 Nov 2015 16:46:10 -0800
changeset 308731 788287eae76366afd74bc7a817682bbf2cfd6f8c
parent 308730 d1f87a9a1795973a6ffa80625b52a725726ea59c
child 308732 a53d7747369c6d4fc12fd89e2cdb8c2c2195725b
push id5513
push userraliiev@mozilla.com
push dateMon, 25 Jan 2016 13:55:34 +0000
treeherdermozilla-beta@5ee97dd05b5c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvalentin
bugs1186783
milestone45.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 1186783 (part 3) - Replace nsBaseHashtable::EnumerateRead() calls in netwerk/ with iterators. r=valentin.
netwerk/cache2/CacheStorageService.cpp
--- a/netwerk/cache2/CacheStorageService.cpp
+++ b/netwerk/cache2/CacheStorageService.cpp
@@ -2043,67 +2043,16 @@ CacheStorageService::SizeOfExcludingThis
 }
 
 size_t
 CacheStorageService::SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const
 {
   return mallocSizeOf(this) + SizeOfExcludingThis(mallocSizeOf);
 }
 
-namespace {
-
-class ReportStorageMemoryData
-{
-public:
-  nsIMemoryReporterCallback *mHandleReport;
-  nsISupports *mData;
-};
-
-PLDHashOperator ReportStorageMemory(const nsACString& aKey,
-                                    CacheEntryTable* aTable,
-                                    void* aClosure)
-{
-  CacheStorageService::Self()->Lock().AssertCurrentThreadOwns();
-
-  size_t size = 0;
-  mozilla::MallocSizeOf mallocSizeOf = CacheStorageService::MallocSizeOf;
-
-  size += aTable->ShallowSizeOfIncludingThis(mallocSizeOf);
-  for (auto iter = aTable->Iter(); !iter.Done(); iter.Next()) {
-    size += iter.Key().SizeOfExcludingThisIfUnshared(mallocSizeOf);
-
-    // Bypass memory-only entries, those will be reported when iterating
-    // the memory only table. Memory-only entries are stored in both ALL_ENTRIES
-    // and MEMORY_ONLY hashtables.
-    RefPtr<mozilla::net::CacheEntry> const& entry = iter.Data();
-    if (aTable->Type() == CacheEntryTable::MEMORY_ONLY ||
-        entry->IsUsingDisk()) {
-      size += entry->SizeOfIncludingThis(mallocSizeOf);
-    }
-  }
-
-  ReportStorageMemoryData& data =
-    *static_cast<ReportStorageMemoryData*>(aClosure);
-  // These key names are not privacy-sensitive.
-  data.mHandleReport->Callback(
-    EmptyCString(),
-    nsPrintfCString("explicit/network/cache2/%s-storage(%s)",
-      aTable->Type() == CacheEntryTable::MEMORY_ONLY ? "memory" : "disk",
-      aKey.BeginReading()),
-    nsIMemoryReporter::KIND_HEAP,
-    nsIMemoryReporter::UNITS_BYTES,
-    size,
-    NS_LITERAL_CSTRING("Memory used by the cache storage."),
-    data.mData);
-
-  return PL_DHASH_NEXT;
-}
-
-} // namespace
-
 NS_IMETHODIMP
 CacheStorageService::CollectReports(nsIMemoryReporterCallback* aHandleReport,
                                     nsISupports* aData, bool aAnonymize)
 {
   nsresult rv;
 
   rv = MOZ_COLLECT_REPORT(
     "explicit/network/cache2/io", KIND_HEAP, UNITS_BYTES,
@@ -2136,20 +2085,50 @@ CacheStorageService::CollectReports(nsIM
   // CacheEntryTable to N CacheEntry
   // CacheEntry to 1 CacheFile
   // CacheFile to
   //   N CacheFileChunk (keeping the actual data)
   //   1 CacheFileMetadata (keeping http headers etc.)
   //   1 CacheFileOutputStream
   //   N CacheFileInputStream
   if (sGlobalEntryTables) {
-    ReportStorageMemoryData data;
-    data.mHandleReport = aHandleReport;
-    data.mData = aData;
-    sGlobalEntryTables->EnumerateRead(&ReportStorageMemory, &data);
+    for (auto iter1 = sGlobalEntryTables->Iter(); !iter1.Done(); iter1.Next()) {
+      CacheStorageService::Self()->Lock().AssertCurrentThreadOwns();
+
+      CacheEntryTable* table = iter1.UserData();
+
+      size_t size = 0;
+      mozilla::MallocSizeOf mallocSizeOf = CacheStorageService::MallocSizeOf;
+
+      size += table->ShallowSizeOfIncludingThis(mallocSizeOf);
+      for (auto iter2 = table->Iter(); !iter2.Done(); iter2.Next()) {
+        size += iter2.Key().SizeOfExcludingThisIfUnshared(mallocSizeOf);
+
+        // Bypass memory-only entries, those will be reported when iterating the
+        // memory only table. Memory-only entries are stored in both ALL_ENTRIES
+        // and MEMORY_ONLY hashtables.
+        RefPtr<mozilla::net::CacheEntry> const& entry = iter2.Data();
+        if (table->Type() == CacheEntryTable::MEMORY_ONLY ||
+            entry->IsUsingDisk()) {
+          size += entry->SizeOfIncludingThis(mallocSizeOf);
+        }
+      }
+
+      // These key names are not privacy-sensitive.
+      aHandleReport->Callback(
+        EmptyCString(),
+        nsPrintfCString("explicit/network/cache2/%s-storage(%s)",
+          table->Type() == CacheEntryTable::MEMORY_ONLY ? "memory" : "disk",
+          iter1.Key().BeginReading()),
+        nsIMemoryReporter::KIND_HEAP,
+        nsIMemoryReporter::UNITS_BYTES,
+        size,
+        NS_LITERAL_CSTRING("Memory used by the cache storage."),
+        aData);
+    }
   }
 
   return NS_OK;
 }
 
 // nsICacheTesting
 
 NS_IMETHODIMP