From c7ac0c2c80c70b906ad1ca1b60cea37ad111661f Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 5 Jan 2022 16:57:16 +0100 Subject: LibJS: Use HashMap::remove_all_matching() in WeakMap --- Userland/Libraries/LibJS/Runtime/WeakMap.cpp | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/WeakMap.cpp b/Userland/Libraries/LibJS/Runtime/WeakMap.cpp index 4a375df62f..9195b4de6c 100644 --- a/Userland/Libraries/LibJS/Runtime/WeakMap.cpp +++ b/Userland/Libraries/LibJS/Runtime/WeakMap.cpp @@ -25,14 +25,9 @@ WeakMap::~WeakMap() void WeakMap::remove_dead_cells(Badge) { - // FIXME: Do this in a single pass. - Vector to_remove; - for (auto& it : m_values) { - if (it.key->state() != Cell::State::Live) - to_remove.append(it.key); - } - for (auto* cell : to_remove) - m_values.remove(cell); + m_values.remove_all_matching([](Cell* key, Value) { + return key->state() != Cell::State::Live; + }); } void WeakMap::visit_edges(Visitor& visitor) -- cgit v1.2.3