From 6c7df1f040e8a4a926eba172c30af2f99a85df04 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 27 Jan 2016 16:05:00 -0800 Subject: [PATCH] Bug 1187151 (part 12) - Replace nsBaseHashtable::Enumerate() calls in dom/ with iterators. r=khuey. --HG-- extra : rebase_source : d3b87524cd3f2eff118727cadac6d31713cead89 --- dom/storage/DOMStorageDBThread.cpp | 71 ++++++++++++------------------ 1 file changed, 28 insertions(+), 43 deletions(-) diff --git a/dom/storage/DOMStorageDBThread.cpp b/dom/storage/DOMStorageDBThread.cpp index 0bb832d924d9..f55f3df2b2cd 100644 --- a/dom/storage/DOMStorageDBThread.cpp +++ b/dom/storage/DOMStorageDBThread.cpp @@ -1207,32 +1207,6 @@ bool OriginPatternMatches(const nsACString& aOriginSuffix, const OriginAttribute return aPattern.Matches(oa); } -PLDHashOperator -ForgetUpdatesForOrigin(const nsACString& aMapping, - nsAutoPtr& aPendingTask, - void* aArg) -{ - DOMStorageDBThread::DBOperation* newOp = static_cast(aArg); - - if (newOp->Type() == DOMStorageDBThread::DBOperation::opClear && - (aPendingTask->OriginNoSuffix() != newOp->OriginNoSuffix() || - aPendingTask->OriginSuffix() != newOp->OriginSuffix())) { - return PL_DHASH_NEXT; - } - - if (newOp->Type() == DOMStorageDBThread::DBOperation::opClearMatchingOrigin && - !StringBeginsWith(aPendingTask->OriginNoSuffix(), newOp->Origin())) { - return PL_DHASH_NEXT; - } - - if (newOp->Type() == DOMStorageDBThread::DBOperation::opClearMatchingOriginAttributes && - !OriginPatternMatches(aPendingTask->OriginSuffix(), newOp->OriginPattern())) { - return PL_DHASH_NEXT; - } - - return PL_DHASH_REMOVE; -} - } // namespace bool @@ -1304,7 +1278,28 @@ DOMStorageDBThread::PendingOperations::Add(DOMStorageDBThread::DBOperation* aOpe // We do this as an optimization as well as a must based on the logic, // if we would not delete the update tasks, changes would have been stored // to the database after clear operations have been executed. - mUpdates.Enumerate(ForgetUpdatesForOrigin, aOperation); + for (auto iter = mUpdates.Iter(); !iter.Done(); iter.Next()) { + nsAutoPtr& pendingTask = iter.Data(); + + if (aOperation->Type() == DBOperation::opClear && + (pendingTask->OriginNoSuffix() != aOperation->OriginNoSuffix() || + pendingTask->OriginSuffix() != aOperation->OriginSuffix())) { + continue; + } + + if (aOperation->Type() == DBOperation::opClearMatchingOrigin && + !StringBeginsWith(pendingTask->OriginNoSuffix(), aOperation->Origin())) { + continue; + } + + if (aOperation->Type() == DBOperation::opClearMatchingOriginAttributes && + !OriginPatternMatches(pendingTask->OriginSuffix(), aOperation->OriginPattern())) { + continue; + } + + iter.Remove(); + } + mClears.Put(aOperation->Target(), aOperation); break; @@ -1321,20 +1316,6 @@ DOMStorageDBThread::PendingOperations::Add(DOMStorageDBThread::DBOperation* aOpe } } -namespace { - -PLDHashOperator -CollectTasks(const nsACString& aMapping, nsAutoPtr& aOperation, void* aArg) -{ - nsTArray >* tasks = - static_cast >*>(aArg); - - tasks->AppendElement(aOperation.forget()); - return PL_DHASH_NEXT; -} - -} // namespace - bool DOMStorageDBThread::PendingOperations::Prepare() { @@ -1345,10 +1326,14 @@ DOMStorageDBThread::PendingOperations::Prepare() // scheduled, we drop all updates matching that scope. So, // all scope-related update operations we have here now were // scheduled after the clear operations. - mClears.Enumerate(CollectTasks, &mExecList); + for (auto iter = mClears.Iter(); !iter.Done(); iter.Next()) { + mExecList.AppendElement(iter.Data().forget()); + } mClears.Clear(); - mUpdates.Enumerate(CollectTasks, &mExecList); + for (auto iter = mUpdates.Iter(); !iter.Done(); iter.Next()) { + mExecList.AppendElement(iter.Data().forget()); + } mUpdates.Clear(); return !!mExecList.Length();