From 3e2de4702c70fb8908f4570c5eca302f7eb20e6f Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 23 Jul 2015 02:35:27 -0700 Subject: [PATCH] Bug 1181443 (part 1) - Use nsTHashtable::Iterator in nsCheapSet. r=froydnj. nsCheapSet is used little enough that I didn't bother creating an iterator for it. I removed the dependency on PLDHashOperator by introducing nsCheapSetOperator, which is equivalent. --HG-- extra : rebase_source : 8a15ae2ee0949a241f6417bfab614affbec2987c --- dom/base/DirectionalityUtils.cpp | 12 ++++++------ xpcom/ds/nsCheapSets.h | 22 ++++++++++++++++++---- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/dom/base/DirectionalityUtils.cpp b/dom/base/DirectionalityUtils.cpp index 753ddbaf31e7..09f4b199fdfa 100644 --- a/dom/base/DirectionalityUtils.cpp +++ b/dom/base/DirectionalityUtils.cpp @@ -490,15 +490,15 @@ private: return map; } - static PLDHashOperator SetNodeDirection(nsPtrHashKey* aEntry, void* aDir) + static nsCheapSetOperator SetNodeDirection(nsPtrHashKey* aEntry, void* aDir) { MOZ_ASSERT(aEntry->GetKey()->IsElement(), "Must be an Element"); aEntry->GetKey()->SetDirectionality(*reinterpret_cast(aDir), true); - return PL_DHASH_NEXT; + return OpNext; } - static PLDHashOperator ResetNodeDirection(nsPtrHashKey* aEntry, void* aData) + static nsCheapSetOperator ResetNodeDirection(nsPtrHashKey* aEntry, void* aData) { MOZ_ASSERT(aEntry->GetKey()->IsElement(), "Must be an Element"); // run the downward propagation algorithm @@ -516,15 +516,15 @@ private: rootNode->ClearHasDirAutoSet(); rootNode->UnsetProperty(nsGkAtoms::dirAutoSetBy); } - return PL_DHASH_REMOVE; + return OpRemove; } - static PLDHashOperator ClearEntry(nsPtrHashKey* aEntry, void* aData) + static nsCheapSetOperator ClearEntry(nsPtrHashKey* aEntry, void* aData) { Element* rootNode = aEntry->GetKey(); rootNode->ClearHasDirAutoSet(); rootNode->UnsetProperty(nsGkAtoms::dirAutoSetBy); - return PL_DHASH_REMOVE; + return OpRemove; } public: diff --git a/xpcom/ds/nsCheapSets.h b/xpcom/ds/nsCheapSets.h index 2ebcc012ab67..e61febffe5a6 100644 --- a/xpcom/ds/nsCheapSets.h +++ b/xpcom/ds/nsCheapSets.h @@ -10,6 +10,12 @@ #include "nsTHashtable.h" #include +enum nsCheapSetOperator +{ + OpNext = 0, // enumerator says continue + OpRemove = 1, // enumerator says remove and continue +}; + /** * A set that takes up minimal size when there are 0 or 1 entries in the set. * Use for cases where sizes of 0 and 1 are even slightly common. @@ -19,7 +25,7 @@ class nsCheapSet { public: typedef typename EntryType::KeyType KeyType; - typedef PLDHashOperator (*Enumerator)(EntryType* aEntry, void* userArg); + typedef nsCheapSetOperator (*Enumerator)(EntryType* aEntry, void* userArg); nsCheapSet() : mState(ZERO) {} ~nsCheapSet() { Clear(); } @@ -70,13 +76,21 @@ public: case ZERO: return 0; case ONE: - if (aEnumFunc(GetSingleEntry(), aUserArg) == PL_DHASH_REMOVE) { + if (aEnumFunc(GetSingleEntry(), aUserArg) == OpRemove) { GetSingleEntry()->~EntryType(); mState = ZERO; } return 1; - case MANY: - return mUnion.table->EnumerateEntries(aEnumFunc, aUserArg); + case MANY: { + uint32_t n = mUnion.table->Count(); + for (auto iter = mUnion.table->Iter(); !iter.Done(); iter.Next()) { + auto entry = static_cast(iter.Get()); + if (aEnumFunc(entry, aUserArg) == OpRemove) { + iter.Remove(); + } + } + return n; + } default: NS_NOTREACHED("bogus state"); return 0;