1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 14:57:35 +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

@ -42,19 +42,17 @@ bool FinalizationRegistry::remove_by_token(Object& unregister_token)
return removed;
}
void FinalizationRegistry::remove_swept_cells(Badge<Heap>, Span<Cell*> cells)
void FinalizationRegistry::remove_dead_cells(Badge<Heap>)
{
auto any_cells_were_swept = false;
for (auto* cell : cells) {
for (auto& record : m_records) {
if (record.target != cell)
continue;
record.target = nullptr;
any_cells_were_swept = true;
break;
}
auto any_cells_were_removed = false;
for (auto& record : m_records) {
if (!record.target || record.target->state() == Cell::State::Live)
continue;
record.target = nullptr;
any_cells_were_removed = true;
break;
}
if (any_cells_were_swept)
if (any_cells_were_removed)
vm().enqueue_finalization_registry_cleanup_job(*this);
}