mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 13:51:41 +00:00
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
This commit is contained in:
parent
b755ef234b
commit
3e2de4702c
@ -490,15 +490,15 @@ private:
|
||||
return map;
|
||||
}
|
||||
|
||||
static PLDHashOperator SetNodeDirection(nsPtrHashKey<Element>* aEntry, void* aDir)
|
||||
static nsCheapSetOperator SetNodeDirection(nsPtrHashKey<Element>* aEntry, void* aDir)
|
||||
{
|
||||
MOZ_ASSERT(aEntry->GetKey()->IsElement(), "Must be an Element");
|
||||
aEntry->GetKey()->SetDirectionality(*reinterpret_cast<Directionality*>(aDir),
|
||||
true);
|
||||
return PL_DHASH_NEXT;
|
||||
return OpNext;
|
||||
}
|
||||
|
||||
static PLDHashOperator ResetNodeDirection(nsPtrHashKey<Element>* aEntry, void* aData)
|
||||
static nsCheapSetOperator ResetNodeDirection(nsPtrHashKey<Element>* 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<Element>* aEntry, void* aData)
|
||||
static nsCheapSetOperator ClearEntry(nsPtrHashKey<Element>* aEntry, void* aData)
|
||||
{
|
||||
Element* rootNode = aEntry->GetKey();
|
||||
rootNode->ClearHasDirAutoSet();
|
||||
rootNode->UnsetProperty(nsGkAtoms::dirAutoSetBy);
|
||||
return PL_DHASH_REMOVE;
|
||||
return OpRemove;
|
||||
}
|
||||
|
||||
public:
|
||||
|
@ -10,6 +10,12 @@
|
||||
#include "nsTHashtable.h"
|
||||
#include <stdint.h>
|
||||
|
||||
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<EntryType*>(iter.Get());
|
||||
if (aEnumFunc(entry, aUserArg) == OpRemove) {
|
||||
iter.Remove();
|
||||
}
|
||||
}
|
||||
return n;
|
||||
}
|
||||
default:
|
||||
NS_NOTREACHED("bogus state");
|
||||
return 0;
|
||||
|
Loading…
Reference in New Issue
Block a user