diff --git a/xpcom/ds/nsCheapSets.h b/xpcom/ds/nsCheapSets.h index 5e39c88a5d22..4912ae7d81f9 100644 --- a/xpcom/ds/nsCheapSets.h +++ b/xpcom/ds/nsCheapSets.h @@ -18,6 +18,7 @@ class nsCheapSet { public: typedef typename EntryType::KeyType KeyType; + typedef PLDHashOperator (* Enumerator)(EntryType* aEntry, void* userArg); nsCheapSet() : mState(ZERO) { @@ -58,6 +59,25 @@ public: } } + uint32_t EnumerateEntries(Enumerator enumFunc, void* userArg) + { + switch (mState) { + case ZERO: + return 0; + case ONE: + if (enumFunc(GetSingleEntry(), userArg) == PL_DHASH_REMOVE) { + GetSingleEntry()->~EntryType(); + mState = ZERO; + } + return 1; + case MANY: + return mUnion.table->EnumerateEntries(enumFunc, userArg); + default: + NS_NOTREACHED("bogus state"); + return 0; + } + } + private: EntryType* GetSingleEntry() {