1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 13:17:35 +00:00

LibJS: Add MarkedVector<T>

This abstracts a vector of Cell* with a strongly typed span() accessor
that gives you Span<T*> instead of Span<Cell*>.

It is intended to replace MarkedValueList in situations where you only
need to store pointers to Cell (or an even more specific type of Cell).

The API can definitely be improved, it's just the bare basics for now.
This commit is contained in:
Andreas Kling 2021-12-16 18:54:06 +01:00
parent c26b58bc53
commit 8bb9fe63b7
6 changed files with 126 additions and 0 deletions

View file

@ -119,6 +119,11 @@ void Heap::gather_roots(HashTable<Cell*>& roots)
}
}
for (auto& vector : m_marked_vectors) {
for (auto* cell : vector.cells())
roots.set(cell);
}
if constexpr (HEAP_DEBUG) {
dbgln("gather_roots:");
for (auto* root : roots)
@ -318,6 +323,18 @@ void Heap::did_destroy_marked_value_list(Badge<MarkedValueList>, MarkedValueList
m_marked_value_lists.remove(list);
}
void Heap::did_create_marked_vector(Badge<MarkedVectorBase>, MarkedVectorBase& vector)
{
VERIFY(!m_marked_vectors.contains(vector));
m_marked_vectors.append(vector);
}
void Heap::did_destroy_marked_vector(Badge<MarkedVectorBase>, MarkedVectorBase& vector)
{
VERIFY(m_marked_vectors.contains(vector));
m_marked_vectors.remove(vector);
}
void Heap::did_create_weak_container(Badge<WeakContainer>, WeakContainer& set)
{
VERIFY(!m_weak_containers.contains(set));