From 470c99a2a6ac793d60a044621681420aef91623b Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 11 Sep 2021 12:02:38 +0200 Subject: [PATCH] LibJS: Tweak the WeakContainer::remove_swept_cells() API a little bit Make this API take a Span instead of a Vector&. This is behavior neutral, but stops the API looking like it wants to do mutable things to the Vector. --- Userland/Libraries/LibJS/Heap/Heap.cpp | 2 +- Userland/Libraries/LibJS/Runtime/FinalizationRegistry.cpp | 4 ++-- Userland/Libraries/LibJS/Runtime/FinalizationRegistry.h | 2 +- Userland/Libraries/LibJS/Runtime/WeakContainer.h | 2 +- Userland/Libraries/LibJS/Runtime/WeakMap.cpp | 2 +- Userland/Libraries/LibJS/Runtime/WeakMap.h | 2 +- Userland/Libraries/LibJS/Runtime/WeakRef.cpp | 2 +- Userland/Libraries/LibJS/Runtime/WeakRef.h | 2 +- Userland/Libraries/LibJS/Runtime/WeakSet.cpp | 2 +- Userland/Libraries/LibJS/Runtime/WeakSet.h | 2 +- 10 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Userland/Libraries/LibJS/Heap/Heap.cpp b/Userland/Libraries/LibJS/Heap/Heap.cpp index d0bc3ba2891..4c5b9292d0a 100644 --- a/Userland/Libraries/LibJS/Heap/Heap.cpp +++ b/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) - weak_container.remove_swept_cells({}, swept_cells); + weak_container.remove_swept_cells({}, swept_cells.span()); if constexpr (HEAP_DEBUG) { for_each_block([&](auto& block) { diff --git a/Userland/Libraries/LibJS/Runtime/FinalizationRegistry.cpp b/Userland/Libraries/LibJS/Runtime/FinalizationRegistry.cpp index 9e012043d6b..01713fa39f7 100644 --- a/Userland/Libraries/LibJS/Runtime/FinalizationRegistry.cpp +++ b/Userland/Libraries/LibJS/Runtime/FinalizationRegistry.cpp @@ -42,10 +42,10 @@ bool FinalizationRegistry::remove_by_token(Object& unregister_token) return removed; } -void FinalizationRegistry::remove_swept_cells(Badge, Vector& cells) +void FinalizationRegistry::remove_swept_cells(Badge, Span cells) { auto any_cells_were_swept = false; - for (auto cell : cells) { + for (auto* cell : cells) { for (auto& record : m_records) { if (record.target != cell) continue; diff --git a/Userland/Libraries/LibJS/Runtime/FinalizationRegistry.h b/Userland/Libraries/LibJS/Runtime/FinalizationRegistry.h index 8753f0838c7..27ef6e16957 100644 --- a/Userland/Libraries/LibJS/Runtime/FinalizationRegistry.h +++ b/Userland/Libraries/LibJS/Runtime/FinalizationRegistry.h @@ -30,7 +30,7 @@ public: bool remove_by_token(Object& unregister_token); void cleanup(FunctionObject* callback = nullptr); - virtual void remove_swept_cells(Badge, Vector&) override; + virtual void remove_swept_cells(Badge, Span) override; private: virtual void visit_edges(Visitor& visitor) override; diff --git a/Userland/Libraries/LibJS/Runtime/WeakContainer.h b/Userland/Libraries/LibJS/Runtime/WeakContainer.h index 8e469fb9ed5..3a5cc8825b1 100644 --- a/Userland/Libraries/LibJS/Runtime/WeakContainer.h +++ b/Userland/Libraries/LibJS/Runtime/WeakContainer.h @@ -15,7 +15,7 @@ public: explicit WeakContainer(Heap&); virtual ~WeakContainer(); - virtual void remove_swept_cells(Badge, Vector&) = 0; + virtual void remove_swept_cells(Badge, Span) = 0; protected: void deregister(); diff --git a/Userland/Libraries/LibJS/Runtime/WeakMap.cpp b/Userland/Libraries/LibJS/Runtime/WeakMap.cpp index d689bb5a970..8bd9a7a9c70 100644 --- a/Userland/Libraries/LibJS/Runtime/WeakMap.cpp +++ b/Userland/Libraries/LibJS/Runtime/WeakMap.cpp @@ -23,7 +23,7 @@ WeakMap::~WeakMap() { } -void WeakMap::remove_swept_cells(Badge, Vector& cells) +void WeakMap::remove_swept_cells(Badge, Span cells) { for (auto* cell : cells) m_values.remove(cell); diff --git a/Userland/Libraries/LibJS/Runtime/WeakMap.h b/Userland/Libraries/LibJS/Runtime/WeakMap.h index e530cb95c10..18a6b74305a 100644 --- a/Userland/Libraries/LibJS/Runtime/WeakMap.h +++ b/Userland/Libraries/LibJS/Runtime/WeakMap.h @@ -27,7 +27,7 @@ public: HashMap const& values() const { return m_values; }; HashMap& values() { return m_values; }; - virtual void remove_swept_cells(Badge, Vector&) override; + virtual void remove_swept_cells(Badge, Span) override; private: HashMap m_values; // This stores Cell pointers instead of Object pointers to aide with sweeping diff --git a/Userland/Libraries/LibJS/Runtime/WeakRef.cpp b/Userland/Libraries/LibJS/Runtime/WeakRef.cpp index 868cea84576..85ac7b6621d 100644 --- a/Userland/Libraries/LibJS/Runtime/WeakRef.cpp +++ b/Userland/Libraries/LibJS/Runtime/WeakRef.cpp @@ -25,7 +25,7 @@ WeakRef::~WeakRef() { } -void WeakRef::remove_swept_cells(Badge, Vector& cells) +void WeakRef::remove_swept_cells(Badge, Span cells) { VERIFY(m_value); for (auto* cell : cells) { diff --git a/Userland/Libraries/LibJS/Runtime/WeakRef.h b/Userland/Libraries/LibJS/Runtime/WeakRef.h index 91c2ddb5511..d93202ed556 100644 --- a/Userland/Libraries/LibJS/Runtime/WeakRef.h +++ b/Userland/Libraries/LibJS/Runtime/WeakRef.h @@ -27,7 +27,7 @@ public: void update_execution_generation() { m_last_execution_generation = vm().execution_generation(); }; - virtual void remove_swept_cells(Badge, Vector&) override; + virtual void remove_swept_cells(Badge, Span) override; private: virtual void visit_edges(Visitor&) override; diff --git a/Userland/Libraries/LibJS/Runtime/WeakSet.cpp b/Userland/Libraries/LibJS/Runtime/WeakSet.cpp index ebf717ffc6f..6d269ea38cf 100644 --- a/Userland/Libraries/LibJS/Runtime/WeakSet.cpp +++ b/Userland/Libraries/LibJS/Runtime/WeakSet.cpp @@ -23,7 +23,7 @@ WeakSet::~WeakSet() { } -void WeakSet::remove_swept_cells(Badge, Vector& cells) +void WeakSet::remove_swept_cells(Badge, Span cells) { for (auto* cell : cells) m_values.remove(cell); diff --git a/Userland/Libraries/LibJS/Runtime/WeakSet.h b/Userland/Libraries/LibJS/Runtime/WeakSet.h index 80bcba5708e..36433f86c56 100644 --- a/Userland/Libraries/LibJS/Runtime/WeakSet.h +++ b/Userland/Libraries/LibJS/Runtime/WeakSet.h @@ -27,7 +27,7 @@ public: HashTable const& values() const { return m_values; }; HashTable& values() { return m_values; }; - virtual void remove_swept_cells(Badge, Vector&) override; + virtual void remove_swept_cells(Badge, Span) override; private: HashTable m_values; // This stores Cell pointers instead of Object pointers to aide with sweeping