mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1182973 - Use nsTHashtable::Iterator in dom/bindings/. r=bz.
Changing the return type of Enumerator from PLDHashOperator to void -- possible because the only such functions always return PL_DHASH_NEXT -- is a double-win here. - It lets us remove the dependency on pldhash.h. - It makes it easier to replace the enumeration with iteration.
This commit is contained in:
parent
025b6f500e
commit
072a8b1aa1
@ -35,7 +35,6 @@
|
||||
#include "qsObjectHelper.h"
|
||||
#include "xpcpublic.h"
|
||||
#include "nsIVariant.h"
|
||||
#include "pldhash.h" // For PLDHashOperator
|
||||
|
||||
#include "nsWrapperCacheInlines.h"
|
||||
|
||||
@ -2146,17 +2145,13 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
// XXXbz It's not clear whether it's better to add a pldhash dependency here
|
||||
// (for PLDHashOperator) or add a BindingUtils.h dependency (for
|
||||
// SequenceTracer) to MozMap.h...
|
||||
template<typename T>
|
||||
static PLDHashOperator
|
||||
static void
|
||||
TraceMozMapValue(T* aValue, void* aClosure)
|
||||
{
|
||||
JSTracer* trc = static_cast<JSTracer*>(aClosure);
|
||||
// Act like it's a one-element sequence to leverage all that infrastructure.
|
||||
SequenceTracer<T>::TraceSequence(trc, aValue, aValue + 1);
|
||||
return PL_DHASH_NEXT;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
@ -89,17 +89,19 @@ public:
|
||||
}
|
||||
|
||||
void GetKeys(nsTArray<nsString>& aKeys) const {
|
||||
// Sadly, EnumerateEntries is not a const method
|
||||
const_cast<SelfType*>(this)->EnumerateEntries(KeyEnumerator, &aKeys);
|
||||
for (auto iter = this->ConstIter(); !iter.Done(); iter.Next()) {
|
||||
aKeys.AppendElement(iter.Get()->GetKey());
|
||||
}
|
||||
}
|
||||
|
||||
// XXXbz we expose this generic enumerator for tracing. Otherwise we'd end up
|
||||
// with a dependency on BindingUtils.h here for the SequenceTracer bits.
|
||||
typedef PLDHashOperator (* Enumerator)(DataType* aValue, void* aClosure);
|
||||
typedef void (* Enumerator)(DataType* aValue, void* aClosure);
|
||||
void EnumerateValues(Enumerator aEnumerator, void *aClosure)
|
||||
{
|
||||
ValueEnumClosure args = { aEnumerator, aClosure };
|
||||
this->EnumerateEntries(ValueEnumerator, &args);
|
||||
for (auto iter = this->Iter(); !iter.Done(); iter.Next()) {
|
||||
aEnumerator(&iter.Get()->mData, aClosure);
|
||||
}
|
||||
}
|
||||
|
||||
MOZ_WARN_UNUSED_RESULT
|
||||
@ -111,27 +113,6 @@ public:
|
||||
}
|
||||
return &ent->mData;
|
||||
}
|
||||
|
||||
private:
|
||||
static PLDHashOperator
|
||||
KeyEnumerator(EntryType* aEntry, void* aClosure)
|
||||
{
|
||||
nsTArray<nsString>& keys = *static_cast<nsTArray<nsString>*>(aClosure);
|
||||
keys.AppendElement(aEntry->GetKey());
|
||||
return PL_DHASH_NEXT;
|
||||
}
|
||||
|
||||
struct ValueEnumClosure {
|
||||
Enumerator mEnumerator;
|
||||
void* mClosure;
|
||||
};
|
||||
|
||||
static PLDHashOperator
|
||||
ValueEnumerator(EntryType* aEntry, void* aClosure)
|
||||
{
|
||||
ValueEnumClosure* enumClosure = static_cast<ValueEnumClosure*>(aClosure);
|
||||
return enumClosure->mEnumerator(&aEntry->mData, enumClosure->mClosure);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
|
Loading…
Reference in New Issue
Block a user