Bug 1186811 (part 3) - Replace nsBaseHashtable::EnumerateRead() calls in dom/storage/ with iterators. r=baku.
authorNicholas Nethercote <nnethercote@mozilla.com>
Sun, 01 Nov 2015 19:35:30 -0800
changeset 273426 0c6c2f077d829bec4921ed4c47df055dd8608470
parent 273425 89352365bed03249cef56c3c87afb4bf43daf813
child 273427 78ffe07a4a498c8284751e4bc04469c2a8daa648
push id68273
push usernnethercote@mozilla.com
push dateFri, 20 Nov 2015 02:17:55 +0000
treeherdermozilla-inbound@78ffe07a4a49 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1186811
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 1186811 (part 3) - Replace nsBaseHashtable::EnumerateRead() calls in dom/storage/ with iterators. r=baku.
dom/storage/DOMStorageCache.cpp
--- a/dom/storage/DOMStorageCache.cpp
+++ b/dom/storage/DOMStorageCache.cpp
@@ -347,62 +347,39 @@ DOMStorageCache::GetLength(const DOMStor
       return mLoadResult;
     }
   }
 
   *aRetval = DataSet(aStorage).mKeys.Count();
   return NS_OK;
 }
 
-namespace {
-
-class IndexFinderData
-{
-public:
-  IndexFinderData(uint32_t aIndex, nsAString& aRetval)
-    : mIndex(aIndex), mKey(aRetval)
-  {
-    mKey.SetIsVoid(true);
-  }
-
-  uint32_t mIndex;
-  nsAString& mKey;
-};
-
-PLDHashOperator
-FindKeyOrder(const nsAString& aKey, const nsString aValue, void* aArg)
-{
-  IndexFinderData* data = static_cast<IndexFinderData*>(aArg);
-
-  if (data->mIndex--) {
-    return PL_DHASH_NEXT;
-  }
-
-  data->mKey = aKey;
-  return PL_DHASH_STOP;
-}
-
-} // namespace
-
 nsresult
 DOMStorageCache::GetKey(const DOMStorage* aStorage, uint32_t aIndex, nsAString& aRetval)
 {
   // XXX: This does a linear search for the key at index, which would
   // suck if there's a large numer of indexes. Do we care? If so,
   // maybe we need to have a lazily populated key array here or
   // something?
   if (Persist(aStorage)) {
     WaitForPreload(Telemetry::LOCALDOMSTORAGE_GETKEY_BLOCKING_MS);
     if (NS_FAILED(mLoadResult)) {
       return mLoadResult;
     }
   }
 
-  IndexFinderData data(aIndex, aRetval);
-  DataSet(aStorage).mKeys.EnumerateRead(FindKeyOrder, &data);
+  aRetval.SetIsVoid(true);
+  for (auto iter = DataSet(aStorage).mKeys.Iter(); !iter.Done(); iter.Next()) {
+    if (aIndex == 0) {
+      aRetval = iter.Key();
+      break;
+    }
+    aIndex--;
+  }
+
   return NS_OK;
 }
 
 namespace {
 
 static PLDHashOperator
 KeysArrayBuilder(const nsAString& aKey, const nsString aValue, void* aArg)
 {