Forráskód Böngészése

LibJS: Tweak the WeakContainer::remove_swept_cells() API a little bit

Make this API take a Span<Cell*> instead of a Vector<Cell*>&.
This is behavior neutral, but stops the API looking like it wants to
do mutable things to the Vector.
Andreas Kling 3 éve
szülő
commit
470c99a2a6

+ 1 - 1
Userland/Libraries/LibJS/Heap/Heap.cpp

@@ -251,7 +251,7 @@ void Heap::sweep_dead_cells(bool print_report, const Core::ElapsedTimer& measure
     }
     }
 
 
     for (auto& weak_container : m_weak_containers)
     for (auto& weak_container : m_weak_containers)
-        weak_container.remove_swept_cells({}, swept_cells);
+        weak_container.remove_swept_cells({}, swept_cells.span());
 
 
     if constexpr (HEAP_DEBUG) {
     if constexpr (HEAP_DEBUG) {
         for_each_block([&](auto& block) {
         for_each_block([&](auto& block) {

+ 2 - 2
Userland/Libraries/LibJS/Runtime/FinalizationRegistry.cpp

@@ -42,10 +42,10 @@ bool FinalizationRegistry::remove_by_token(Object& unregister_token)
     return removed;
     return removed;
 }
 }
 
 
-void FinalizationRegistry::remove_swept_cells(Badge<Heap>, Vector<Cell*>& cells)
+void FinalizationRegistry::remove_swept_cells(Badge<Heap>, Span<Cell*> cells)
 {
 {
     auto any_cells_were_swept = false;
     auto any_cells_were_swept = false;
-    for (auto cell : cells) {
+    for (auto* cell : cells) {
         for (auto& record : m_records) {
         for (auto& record : m_records) {
             if (record.target != cell)
             if (record.target != cell)
                 continue;
                 continue;

+ 1 - 1
Userland/Libraries/LibJS/Runtime/FinalizationRegistry.h

@@ -30,7 +30,7 @@ public:
     bool remove_by_token(Object& unregister_token);
     bool remove_by_token(Object& unregister_token);
     void cleanup(FunctionObject* callback = nullptr);
     void cleanup(FunctionObject* callback = nullptr);
 
 
-    virtual void remove_swept_cells(Badge<Heap>, Vector<Cell*>&) override;
+    virtual void remove_swept_cells(Badge<Heap>, Span<Cell*>) override;
 
 
 private:
 private:
     virtual void visit_edges(Visitor& visitor) override;
     virtual void visit_edges(Visitor& visitor) override;

+ 1 - 1
Userland/Libraries/LibJS/Runtime/WeakContainer.h

@@ -15,7 +15,7 @@ public:
     explicit WeakContainer(Heap&);
     explicit WeakContainer(Heap&);
     virtual ~WeakContainer();
     virtual ~WeakContainer();
 
 
-    virtual void remove_swept_cells(Badge<Heap>, Vector<Cell*>&) = 0;
+    virtual void remove_swept_cells(Badge<Heap>, Span<Cell*>) = 0;
 
 
 protected:
 protected:
     void deregister();
     void deregister();

+ 1 - 1
Userland/Libraries/LibJS/Runtime/WeakMap.cpp

@@ -23,7 +23,7 @@ WeakMap::~WeakMap()
 {
 {
 }
 }
 
 
-void WeakMap::remove_swept_cells(Badge<Heap>, Vector<Cell*>& cells)
+void WeakMap::remove_swept_cells(Badge<Heap>, Span<Cell*> cells)
 {
 {
     for (auto* cell : cells)
     for (auto* cell : cells)
         m_values.remove(cell);
         m_values.remove(cell);

+ 1 - 1
Userland/Libraries/LibJS/Runtime/WeakMap.h

@@ -27,7 +27,7 @@ public:
     HashMap<Cell*, Value> const& values() const { return m_values; };
     HashMap<Cell*, Value> const& values() const { return m_values; };
     HashMap<Cell*, Value>& values() { return m_values; };
     HashMap<Cell*, Value>& values() { return m_values; };
 
 
-    virtual void remove_swept_cells(Badge<Heap>, Vector<Cell*>&) override;
+    virtual void remove_swept_cells(Badge<Heap>, Span<Cell*>) override;
 
 
 private:
 private:
     HashMap<Cell*, Value> m_values; // This stores Cell pointers instead of Object pointers to aide with sweeping
     HashMap<Cell*, Value> m_values; // This stores Cell pointers instead of Object pointers to aide with sweeping

+ 1 - 1
Userland/Libraries/LibJS/Runtime/WeakRef.cpp

@@ -25,7 +25,7 @@ WeakRef::~WeakRef()
 {
 {
 }
 }
 
 
-void WeakRef::remove_swept_cells(Badge<Heap>, Vector<Cell*>& cells)
+void WeakRef::remove_swept_cells(Badge<Heap>, Span<Cell*> cells)
 {
 {
     VERIFY(m_value);
     VERIFY(m_value);
     for (auto* cell : cells) {
     for (auto* cell : cells) {

+ 1 - 1
Userland/Libraries/LibJS/Runtime/WeakRef.h

@@ -27,7 +27,7 @@ public:
 
 
     void update_execution_generation() { m_last_execution_generation = vm().execution_generation(); };
     void update_execution_generation() { m_last_execution_generation = vm().execution_generation(); };
 
 
-    virtual void remove_swept_cells(Badge<Heap>, Vector<Cell*>&) override;
+    virtual void remove_swept_cells(Badge<Heap>, Span<Cell*>) override;
 
 
 private:
 private:
     virtual void visit_edges(Visitor&) override;
     virtual void visit_edges(Visitor&) override;

+ 1 - 1
Userland/Libraries/LibJS/Runtime/WeakSet.cpp

@@ -23,7 +23,7 @@ WeakSet::~WeakSet()
 {
 {
 }
 }
 
 
-void WeakSet::remove_swept_cells(Badge<Heap>, Vector<Cell*>& cells)
+void WeakSet::remove_swept_cells(Badge<Heap>, Span<Cell*> cells)
 {
 {
     for (auto* cell : cells)
     for (auto* cell : cells)
         m_values.remove(cell);
         m_values.remove(cell);

+ 1 - 1
Userland/Libraries/LibJS/Runtime/WeakSet.h

@@ -27,7 +27,7 @@ public:
     HashTable<Cell*> const& values() const { return m_values; };
     HashTable<Cell*> const& values() const { return m_values; };
     HashTable<Cell*>& values() { return m_values; };
     HashTable<Cell*>& values() { return m_values; };
 
 
-    virtual void remove_swept_cells(Badge<Heap>, Vector<Cell*>&) override;
+    virtual void remove_swept_cells(Badge<Heap>, Span<Cell*>) override;
 
 
 private:
 private:
     HashTable<Cell*> m_values; // This stores Cell pointers instead of Object pointers to aide with sweeping
     HashTable<Cell*> m_values; // This stores Cell pointers instead of Object pointers to aide with sweeping