Bug 1186809 (part 1) - Replace nsBaseHashtable::EnumerateRead() calls in dom/quota/ with iterators. r=janv.
authorNicholas Nethercote <nnethercote@mozilla.com>
Tue, 03 Nov 2015 15:42:40 -0800
changeset 272053 2f1e73d59cb2853d78ab0d9d3078f61fa675535e
parent 272052 1a90a4d33cbb2980b632eaae6e16a1f93fca533f
child 272054 bb38548f7e3309c0fc3f1e33b899420388f707a8
push id29659
push usercbook@mozilla.com
push dateWed, 11 Nov 2015 11:43:09 +0000
treeherdermozilla-central@84a7cf29f4f1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjanv
bugs1186809
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 1186809 (part 1) - Replace nsBaseHashtable::EnumerateRead() calls in dom/quota/ with iterators. r=janv.
dom/quota/QuotaManager.cpp
--- a/dom/quota/QuotaManager.cpp
+++ b/dom/quota/QuotaManager.cpp
@@ -2226,61 +2226,18 @@ QuotaManager::RemovePendingDirectoryLock
 uint64_t
 QuotaManager::CollectOriginsForEviction(
                                   uint64_t aMinSizeToBeFreed,
                                   nsTArray<RefPtr<DirectoryLockImpl>>& aLocks)
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(aLocks.IsEmpty());
 
-  class MOZ_STACK_CLASS Closure final
+  struct MOZ_STACK_CLASS Helper final
   {
-    nsTArray<DirectoryLockImpl*>& mTemporaryStorageLocks;
-    nsTArray<DirectoryLockImpl*>& mDefaultStorageLocks;
-    nsTArray<OriginInfo*>& mInactiveOriginInfos;
-
-  public:
-    Closure(nsTArray<DirectoryLockImpl*>& aTemporaryStorageLocks,
-            nsTArray<DirectoryLockImpl*>& aDefaultStorageLocks,
-            nsTArray<OriginInfo*>& aInactiveOriginInfos)
-      : mTemporaryStorageLocks(aTemporaryStorageLocks)
-      , mDefaultStorageLocks(aDefaultStorageLocks)
-      , mInactiveOriginInfos(aInactiveOriginInfos)
-    { }
-
-    static PLDHashOperator
-    GetInactiveTemporaryStorageOrigins(const nsACString& aKey,
-                                       GroupInfoPair* aValue,
-                                       void* aUserArg)
-    {
-      MOZ_ASSERT(!aKey.IsEmpty());
-      MOZ_ASSERT(aValue);
-      MOZ_ASSERT(aUserArg);
-
-      auto* closure = static_cast<Closure*>(aUserArg);
-
-      RefPtr<GroupInfo> groupInfo =
-        aValue->LockedGetGroupInfo(PERSISTENCE_TYPE_TEMPORARY);
-      if (groupInfo) {
-        GetInactiveOriginInfos(groupInfo->mOriginInfos,
-                               closure->mTemporaryStorageLocks,
-                               closure->mInactiveOriginInfos);
-      }
-
-      groupInfo = aValue->LockedGetGroupInfo(PERSISTENCE_TYPE_DEFAULT);
-      if (groupInfo) {
-        GetInactiveOriginInfos(groupInfo->mOriginInfos,
-                               closure->mDefaultStorageLocks,
-                               closure->mInactiveOriginInfos);
-      }
-
-      return PL_DHASH_NEXT;
-    }
-
-  private:
     static void
     GetInactiveOriginInfos(nsTArray<RefPtr<OriginInfo>>& aOriginInfos,
                            nsTArray<DirectoryLockImpl*>& aLocks,
                            nsTArray<OriginInfo*>& aInactiveOriginInfos)
     {
       for (OriginInfo* originInfo : aOriginInfos) {
         MOZ_ASSERT(IsTreatedAsTemporary(originInfo->mGroupInfo->mPersistenceType,
                                         originInfo->mIsApp));
@@ -2326,24 +2283,41 @@ QuotaManager::CollectOriginsForEviction(
       MOZ_ASSERT(persistenceType.Value() == PERSISTENCE_TYPE_PERSISTENT);
 
       // Do nothing here, persistent origins don't need to be collected ever.
     }
   }
 
   nsTArray<OriginInfo*> inactiveOrigins;
 
-  Closure closure(temporaryStorageLocks, defaultStorageLocks, inactiveOrigins);
-
   // Enumerate and process inactive origins. This must be protected by the
   // mutex.
   MutexAutoLock lock(mQuotaMutex);
 
-  mGroupInfoPairs.EnumerateRead(Closure::GetInactiveTemporaryStorageOrigins,
-                                &closure);
+  for (auto iter = mGroupInfoPairs.Iter(); !iter.Done(); iter.Next()) {
+    GroupInfoPair* pair = iter.UserData();
+
+    MOZ_ASSERT(!iter.Key().IsEmpty());
+    MOZ_ASSERT(pair);
+
+    RefPtr<GroupInfo> groupInfo =
+      pair->LockedGetGroupInfo(PERSISTENCE_TYPE_TEMPORARY);
+    if (groupInfo) {
+      Helper::GetInactiveOriginInfos(groupInfo->mOriginInfos,
+                                     temporaryStorageLocks,
+                                     inactiveOrigins);
+    }
+
+    groupInfo = pair->LockedGetGroupInfo(PERSISTENCE_TYPE_DEFAULT);
+    if (groupInfo) {
+      Helper::GetInactiveOriginInfos(groupInfo->mOriginInfos,
+                                     defaultStorageLocks,
+                                     inactiveOrigins);
+    }
+  }
 
 #ifdef DEBUG
   // Make sure the array is sorted correctly.
   for (uint32_t index = inactiveOrigins.Length(); index > 1; index--) {
     MOZ_ASSERT(inactiveOrigins[index - 1]->mAccessTime >=
                inactiveOrigins[index - 2]->mAccessTime);
   }
 #endif