diff options
author | Andreas Kling <kling@serenityos.org> | 2021-10-05 18:44:31 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-10-05 18:52:00 +0200 |
commit | 83bd6754776e8f3290c460feb28f261cffad6a9b (patch) | |
tree | 236fe3c0ee94d97c6c19cb1428c535edb3e5eb64 /Userland/Libraries/LibJS/Runtime/FinalizationRegistry.cpp | |
parent | 19fc225b455957cf81d2038571a7f3713c01b555 (diff) | |
download | serenity-83bd6754776e8f3290c460feb28f261cffad6a9b.zip |
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.
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime/FinalizationRegistry.cpp')
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/FinalizationRegistry.cpp | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/FinalizationRegistry.cpp b/Userland/Libraries/LibJS/Runtime/FinalizationRegistry.cpp index 0a57afea56..25c6486033 100644 --- a/Userland/Libraries/LibJS/Runtime/FinalizationRegistry.cpp +++ b/Userland/Libraries/LibJS/Runtime/FinalizationRegistry.cpp @@ -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); } |