Bug 1187134 (part 4) - Replace nsBaseHashtable::Enumerate() calls in netwerk/cache{,2}/ with iterators. r=valentin.
authorNicholas Nethercote <nnethercote@mozilla.com>
Thu, 03 Dec 2015 14:00:03 -0800
changeset 309736 3de19e88a9d27f53055a2991473325bc9fe6465c
parent 309735 5d83cecbfc927b08895ba735de34dc1673e38d98
child 309737 11db77ba981c464300c7e09a282c52a9ea38fbd1
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
bugs1187134
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 1187134 (part 4) - Replace nsBaseHashtable::Enumerate() calls in netwerk/cache{,2}/ with iterators. r=valentin.
netwerk/cache2/CacheFile.cpp
netwerk/cache2/CacheFile.h
--- a/netwerk/cache2/CacheFile.cpp
+++ b/netwerk/cache2/CacheFile.cpp
@@ -877,17 +877,17 @@ CacheFile::ThrowMemoryCachedData()
     LOG(("CacheFile::ThrowMemoryCachedData() - Ignoring request because the "
          "entry is still opening the file [this=%p]", this));
 
     return NS_ERROR_ABORT;
   }
 
   // We cannot release all cached chunks since we need to keep preloaded chunks
   // in memory. See initialization of mPreloadChunkCount for explanation.
-  mCachedChunks.Enumerate(&CacheFile::CleanUpCachedChunks, this);
+  CleanUpCachedChunks();
 
   return NS_OK;
 }
 
 nsresult
 CacheFile::GetElement(const char *aKey, char **_retval)
 {
   CacheFileAutoLock lock(this);
@@ -1582,17 +1582,17 @@ CacheFile::RemoveInput(CacheFileInputStr
 
   ReleaseOutsideLock(already_AddRefed<nsIInputStream>(static_cast<nsIInputStream*>(aInput)));
 
   if (!mMemoryOnly)
     WriteMetadataIfNeededLocked();
 
   // If the input didn't read all data, there might be left some preloaded
   // chunks that won't be used anymore.
-  mCachedChunks.Enumerate(&CacheFile::CleanUpCachedChunks, this);
+  CleanUpCachedChunks();
 
   Telemetry::Accumulate(Telemetry::NETWORK_CACHE_V2_INPUT_STREAM_STATUS,
                         StatusToTelemetryEnum(aStatus));
 
   return NS_OK;
 }
 
 nsresult
@@ -1890,33 +1890,34 @@ CacheFile::FailUpdateListeners(
 
   if (aChunk->IsReady()) {
     aChunk->NotifyUpdateListeners();
   }
 
   return PL_DHASH_NEXT;
 }
 
-PLDHashOperator
-CacheFile::CleanUpCachedChunks(const uint32_t& aIdx,
-                               RefPtr<CacheFileChunk>& aChunk,
-                               void* aClosure)
+void
+CacheFile::CleanUpCachedChunks()
 {
-  CacheFile *file = static_cast<CacheFile*>(aClosure);
+  for (auto iter = mCachedChunks.Iter(); !iter.Done(); iter.Next()) {
+    uint32_t idx = iter.Key();
+    const RefPtr<CacheFileChunk>& chunk = iter.Data();
 
-  LOG(("CacheFile::CleanUpCachedChunks() [this=%p, idx=%u, chunk=%p]", file,
-       aIdx, aChunk.get()));
+    LOG(("CacheFile::CleanUpCachedChunks() [this=%p, idx=%u, chunk=%p]", this,
+         idx, chunk.get()));
 
-  if (file->MustKeepCachedChunk(aIdx)) {
-    LOG(("CacheFile::CleanUpCachedChunks() - Keeping chunk"));
-    return PL_DHASH_NEXT;
+    if (MustKeepCachedChunk(idx)) {
+      LOG(("CacheFile::CleanUpCachedChunks() - Keeping chunk"));
+      continue;
+    }
+
+    LOG(("CacheFile::CleanUpCachedChunks() - Removing chunk"));
+    iter.Remove();
   }
-
-  LOG(("CacheFile::CleanUpCachedChunks() - Removing chunk"));
-  return PL_DHASH_REMOVE;
 }
 
 nsresult
 CacheFile::PadChunkWithZeroes(uint32_t aChunkIdx)
 {
   AssertOwnsLock();
 
   // This method is used to pad last incomplete chunk with zeroes or create
--- a/netwerk/cache2/CacheFile.h
+++ b/netwerk/cache2/CacheFile.h
@@ -168,19 +168,17 @@ private:
   void WriteMetadataIfNeeded();
   void WriteMetadataIfNeededLocked(bool aFireAndForget = false);
   void PostWriteTimer();
 
   static PLDHashOperator FailUpdateListeners(const uint32_t& aIdx,
                                              RefPtr<CacheFileChunk>& aChunk,
                                              void* aClosure);
 
-  static PLDHashOperator CleanUpCachedChunks(const uint32_t& aIdx,
-                                             RefPtr<CacheFileChunk>& aChunk,
-                                             void* aClosure);
+  void CleanUpCachedChunks();
 
   nsresult PadChunkWithZeroes(uint32_t aChunkIdx);
 
   void SetError(nsresult aStatus);
 
   nsresult InitIndexEntry();
 
   mozilla::Mutex mLock;