Bug 1894012 - Part 0: Add needsSweep method for GC hash tables r=sfink

This is follow on from bug 1894012. This allows hash tables to be used as
keys and values in hash tables that are used with WeakCache as we'll do in
these patches.

Differential Revision: https://phabricator.services.mozilla.com/D210504
This commit is contained in:
Jon Coppeard 2024-05-16 15:27:11 +00:00
parent 1f46481d6c
commit 7ce6e5a4f1

View file

@ -96,6 +96,16 @@ class GCHashMap : public js::HashMap<Key, Value, HashPolicy, AllocPolicy> {
}
}
bool needsSweep(JSTracer* trc) const {
for (auto r = this->all(); !r.empty(); r.popFront()) {
if (MapEntryGCPolicy::needsSweep(trc, &r.front().key(),
&r.front().value())) {
return true;
}
}
return false;
}
// GCHashMap is movable
GCHashMap(GCHashMap&& rhs) : Base(std::move(rhs)) {}
void operator=(GCHashMap&& rhs) {
@ -274,6 +284,15 @@ class GCHashSet : public js::HashSet<T, HashPolicy, AllocPolicy> {
}
}
bool needsSweep(JSTracer* trc) const {
for (auto r = this->all(); !r.empty(); r.popFront()) {
if (GCPolicy<T>::needsSweep(trc, &r.front())) {
return true;
}
}
return false;
}
// GCHashSet is movable
GCHashSet(GCHashSet&& rhs) : Base(std::move(rhs)) {}
void operator=(GCHashSet&& rhs) {