Преглед изворни кода

LibJS: Use HashMap::remove_all_matching() in WeakMap

Andreas Kling пре 3 година
родитељ
комит
c7ac0c2c80
1 измењених фајлова са 3 додато и 8 уклоњено
  1. 3 8
      Userland/Libraries/LibJS/Runtime/WeakMap.cpp

+ 3 - 8
Userland/Libraries/LibJS/Runtime/WeakMap.cpp

@@ -25,14 +25,9 @@ WeakMap::~WeakMap()
 
 
 void WeakMap::remove_dead_cells(Badge<Heap>)
 void WeakMap::remove_dead_cells(Badge<Heap>)
 {
 {
-    // FIXME: Do this in a single pass.
-    Vector<Cell*> 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)
 void WeakMap::visit_edges(Visitor& visitor)