From f01997aef8682bbfc8c55a90434d15527152c068 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 18 Nov 2015 21:04:22 -0800 Subject: [PATCH] Bug 1187116 (part 6) - Replace nsBaseHashtable::EnumerateRead() calls in dom/indexedDB/ with iterators. r=khuey. --- dom/indexedDB/ActorsParent.cpp | 166 ++++++++++++--------------------- 1 file changed, 61 insertions(+), 105 deletions(-) diff --git a/dom/indexedDB/ActorsParent.cpp b/dom/indexedDB/ActorsParent.cpp index 094e237f937..8250c9b6d58 100644 --- a/dom/indexedDB/ActorsParent.cpp +++ b/dom/indexedDB/ActorsParent.cpp @@ -21028,110 +21028,6 @@ OpenDatabaseOp::AssertMetadataConsistency(const FullDatabaseMetadata* aMetadata) { AssertIsOnBackgroundThread(); - class MOZ_STACK_CLASS Helper final - { - const ObjectStoreTable& mOtherObjectStores; - IndexTable* mCurrentOtherIndexTable; - - public: - static void - AssertConsistent(const ObjectStoreTable& aThisObjectStores, - const ObjectStoreTable& aOtherObjectStores) - { - Helper helper(aOtherObjectStores); - aThisObjectStores.EnumerateRead(Enumerate, &helper); - } - - private: - explicit Helper(const ObjectStoreTable& aOtherObjectStores) - : mOtherObjectStores(aOtherObjectStores) - , mCurrentOtherIndexTable(nullptr) - { } - - static PLDHashOperator - Enumerate(const uint64_t& /* aKey */, - FullObjectStoreMetadata* aThisObjectStore, - void* aClosure) - { - MOZ_ASSERT(aThisObjectStore); - MOZ_ASSERT(!aThisObjectStore->mDeleted); - MOZ_ASSERT(aClosure); - - auto* helper = static_cast(aClosure); - - MOZ_ASSERT(!helper->mCurrentOtherIndexTable); - - auto* otherObjectStore = - MetadataNameOrIdMatcher::Match( - helper->mOtherObjectStores, aThisObjectStore->mCommonMetadata.id()); - MOZ_ASSERT(otherObjectStore); - - MOZ_ASSERT(aThisObjectStore != otherObjectStore); - - MOZ_ASSERT(aThisObjectStore->mCommonMetadata.id() == - otherObjectStore->mCommonMetadata.id()); - MOZ_ASSERT(aThisObjectStore->mCommonMetadata.name() == - otherObjectStore->mCommonMetadata.name()); - MOZ_ASSERT(aThisObjectStore->mCommonMetadata.autoIncrement() == - otherObjectStore->mCommonMetadata.autoIncrement()); - MOZ_ASSERT(aThisObjectStore->mCommonMetadata.keyPath() == - otherObjectStore->mCommonMetadata.keyPath()); - // mNextAutoIncrementId and mComittedAutoIncrementId may be modified - // concurrently with this OpenOp, so it is not possible to assert equality - // here. - MOZ_ASSERT(aThisObjectStore->mNextAutoIncrementId <= - otherObjectStore->mNextAutoIncrementId); - MOZ_ASSERT(aThisObjectStore->mComittedAutoIncrementId <= - otherObjectStore->mComittedAutoIncrementId); - MOZ_ASSERT(!otherObjectStore->mDeleted); - - MOZ_ASSERT(aThisObjectStore->mIndexes.Count() == - otherObjectStore->mIndexes.Count()); - - AutoRestore ar(helper->mCurrentOtherIndexTable); - helper->mCurrentOtherIndexTable = &otherObjectStore->mIndexes; - - aThisObjectStore->mIndexes.EnumerateRead(Enumerate, helper); - - return PL_DHASH_NEXT; - } - - static PLDHashOperator - Enumerate(const uint64_t& /* aKey */, - FullIndexMetadata* aThisIndex, - void* aClosure) - { - MOZ_ASSERT(aThisIndex); - MOZ_ASSERT(!aThisIndex->mDeleted); - MOZ_ASSERT(aClosure); - - auto* helper = static_cast(aClosure); - - MOZ_ASSERT(helper->mCurrentOtherIndexTable); - - auto* otherIndex = - MetadataNameOrIdMatcher::Match( - *helper->mCurrentOtherIndexTable, aThisIndex->mCommonMetadata.id()); - MOZ_ASSERT(otherIndex); - - MOZ_ASSERT(aThisIndex != otherIndex); - - MOZ_ASSERT(aThisIndex->mCommonMetadata.id() == - otherIndex->mCommonMetadata.id()); - MOZ_ASSERT(aThisIndex->mCommonMetadata.name() == - otherIndex->mCommonMetadata.name()); - MOZ_ASSERT(aThisIndex->mCommonMetadata.keyPath() == - otherIndex->mCommonMetadata.keyPath()); - MOZ_ASSERT(aThisIndex->mCommonMetadata.unique() == - otherIndex->mCommonMetadata.unique()); - MOZ_ASSERT(aThisIndex->mCommonMetadata.multiEntry() == - otherIndex->mCommonMetadata.multiEntry()); - MOZ_ASSERT(!otherIndex->mDeleted); - - return PL_DHASH_NEXT; - } - }; - const FullDatabaseMetadata* thisDB = mMetadata; const FullDatabaseMetadata* otherDB = aMetadata; @@ -21156,7 +21052,67 @@ OpenDatabaseOp::AssertMetadataConsistency(const FullDatabaseMetadata* aMetadata) MOZ_ASSERT(thisDB->mObjectStores.Count() == otherDB->mObjectStores.Count()); - Helper::AssertConsistent(thisDB->mObjectStores, otherDB->mObjectStores); + for (auto objectStoreIter = thisDB->mObjectStores.ConstIter(); + !objectStoreIter.Done(); + objectStoreIter.Next()) { + FullObjectStoreMetadata* thisObjectStore = objectStoreIter.UserData(); + MOZ_ASSERT(thisObjectStore); + MOZ_ASSERT(!thisObjectStore->mDeleted); + + auto* otherObjectStore = + MetadataNameOrIdMatcher::Match( + otherDB->mObjectStores, thisObjectStore->mCommonMetadata.id()); + MOZ_ASSERT(otherObjectStore); + + MOZ_ASSERT(thisObjectStore != otherObjectStore); + + MOZ_ASSERT(thisObjectStore->mCommonMetadata.id() == + otherObjectStore->mCommonMetadata.id()); + MOZ_ASSERT(thisObjectStore->mCommonMetadata.name() == + otherObjectStore->mCommonMetadata.name()); + MOZ_ASSERT(thisObjectStore->mCommonMetadata.autoIncrement() == + otherObjectStore->mCommonMetadata.autoIncrement()); + MOZ_ASSERT(thisObjectStore->mCommonMetadata.keyPath() == + otherObjectStore->mCommonMetadata.keyPath()); + // mNextAutoIncrementId and mComittedAutoIncrementId may be modified + // concurrently with this OpenOp, so it is not possible to assert equality + // here. + MOZ_ASSERT(thisObjectStore->mNextAutoIncrementId <= + otherObjectStore->mNextAutoIncrementId); + MOZ_ASSERT(thisObjectStore->mComittedAutoIncrementId <= + otherObjectStore->mComittedAutoIncrementId); + MOZ_ASSERT(!otherObjectStore->mDeleted); + + MOZ_ASSERT(thisObjectStore->mIndexes.Count() == + otherObjectStore->mIndexes.Count()); + + for (auto indexIter = thisObjectStore->mIndexes.Iter(); + !indexIter.Done(); + indexIter.Next()) { + FullIndexMetadata* thisIndex = indexIter.UserData(); + MOZ_ASSERT(thisIndex); + MOZ_ASSERT(!thisIndex->mDeleted); + + auto* otherIndex = + MetadataNameOrIdMatcher:: + Match(otherObjectStore->mIndexes, thisIndex->mCommonMetadata.id()); + MOZ_ASSERT(otherIndex); + + MOZ_ASSERT(thisIndex != otherIndex); + + MOZ_ASSERT(thisIndex->mCommonMetadata.id() == + otherIndex->mCommonMetadata.id()); + MOZ_ASSERT(thisIndex->mCommonMetadata.name() == + otherIndex->mCommonMetadata.name()); + MOZ_ASSERT(thisIndex->mCommonMetadata.keyPath() == + otherIndex->mCommonMetadata.keyPath()); + MOZ_ASSERT(thisIndex->mCommonMetadata.unique() == + otherIndex->mCommonMetadata.unique()); + MOZ_ASSERT(thisIndex->mCommonMetadata.multiEntry() == + otherIndex->mCommonMetadata.multiEntry()); + MOZ_ASSERT(!otherIndex->mDeleted); + } + } } #endif // DEBUG