diff --git a/netwerk/cache2/CacheFile.cpp b/netwerk/cache2/CacheFile.cpp index 224523ab190..1b9a1ddf823 100644 --- a/netwerk/cache2/CacheFile.cpp +++ b/netwerk/cache2/CacheFile.cpp @@ -882,7 +882,7 @@ CacheFile::ThrowMemoryCachedData() // 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; } @@ -1587,7 +1587,7 @@ CacheFile::RemoveInput(CacheFileInputStream *aInput, nsresult aStatus) // 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)); @@ -1895,23 +1895,24 @@ CacheFile::FailUpdateListeners( return PL_DHASH_NEXT; } -PLDHashOperator -CacheFile::CleanUpCachedChunks(const uint32_t& aIdx, - RefPtr& aChunk, - void* aClosure) +void +CacheFile::CleanUpCachedChunks() { - CacheFile *file = static_cast(aClosure); + for (auto iter = mCachedChunks.Iter(); !iter.Done(); iter.Next()) { + uint32_t idx = iter.Key(); + const RefPtr& 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 diff --git a/netwerk/cache2/CacheFile.h b/netwerk/cache2/CacheFile.h index b2ded77dc6d..826b0ce74c9 100644 --- a/netwerk/cache2/CacheFile.h +++ b/netwerk/cache2/CacheFile.h @@ -173,9 +173,7 @@ private: RefPtr& aChunk, void* aClosure); - static PLDHashOperator CleanUpCachedChunks(const uint32_t& aIdx, - RefPtr& aChunk, - void* aClosure); + void CleanUpCachedChunks(); nsresult PadChunkWithZeroes(uint32_t aChunkIdx);