1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 21:08:12 +00:00

LibJS: Make WeakContainer pruning do less work

Instead of iterating *all* swept cells when pruning weak containers,
only iterate the cells actually *in* the container.

Also, instead of compiling a list of all swept cells, we can simply
check the Cell::state() flag to know if something should be pruned.
This commit is contained in:
Andreas Kling 2021-10-05 18:44:31 +02:00
parent 19fc225b45
commit 83bd675477
10 changed files with 39 additions and 35 deletions

View file

@ -25,18 +25,16 @@ WeakRef::~WeakRef()
{
}
void WeakRef::remove_swept_cells(Badge<Heap>, Span<Cell*> cells)
void WeakRef::remove_dead_cells(Badge<Heap>)
{
VERIFY(m_value);
for (auto* cell : cells) {
if (m_value != cell)
continue;
m_value = nullptr;
// This is an optimization, we deregister from the garbage collector early (even if we were not garbage collected ourself yet)
// to reduce the garbage collection overhead, which we can do because a cleared weak ref cannot be reused.
WeakContainer::deregister();
break;
}
if (m_value->state() == Cell::State::Live)
return;
m_value = nullptr;
// This is an optimization, we deregister from the garbage collector early (even if we were not garbage collected ourself yet)
// to reduce the garbage collection overhead, which we can do because a cleared weak ref cannot be reused.
WeakContainer::deregister();
}
void WeakRef::visit_edges(Visitor& visitor)