mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-05 15:49:11 +00:00
LibGC+Everywhere: Factor out a LibGC from LibJS
Resulting in a massive rename across almost everywhere! Alongside the namespace change, we now have the following names: * JS::NonnullGCPtr -> GC::Ref * JS::GCPtr -> GC::Ptr * JS::HeapFunction -> GC::Function * JS::CellImpl -> GC::Cell * JS::Handle -> GC::Root
This commit is contained in:
parent
ce23efc5f6
commit
f87041bf3a
Notes:
github-actions[bot]
2024-11-15 13:50:17 +00:00
Author: https://github.com/shannonbooth
Commit: f87041bf3a
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2345
1722 changed files with 9939 additions and 9906 deletions
77
Libraries/LibGC/ConservativeVector.h
Normal file
77
Libraries/LibGC/ConservativeVector.h
Normal file
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
* Copyright (c) 2024, Andreas Kling <andreas@ladybird.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/HashMap.h>
|
||||
#include <AK/IntrusiveList.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <LibGC/Cell.h>
|
||||
#include <LibGC/Forward.h>
|
||||
#include <LibGC/HeapRoot.h>
|
||||
|
||||
namespace GC {
|
||||
|
||||
class ConservativeVectorBase {
|
||||
public:
|
||||
virtual ReadonlySpan<FlatPtr> possible_values() const = 0;
|
||||
|
||||
protected:
|
||||
explicit ConservativeVectorBase(Heap&);
|
||||
~ConservativeVectorBase();
|
||||
|
||||
ConservativeVectorBase& operator=(ConservativeVectorBase const&);
|
||||
|
||||
Heap* m_heap { nullptr };
|
||||
IntrusiveListNode<ConservativeVectorBase> m_list_node;
|
||||
|
||||
public:
|
||||
using List = IntrusiveList<&ConservativeVectorBase::m_list_node>;
|
||||
};
|
||||
|
||||
template<typename T, size_t inline_capacity>
|
||||
class ConservativeVector final
|
||||
: public ConservativeVectorBase
|
||||
, public Vector<T, inline_capacity> {
|
||||
|
||||
public:
|
||||
explicit ConservativeVector(Heap& heap)
|
||||
: ConservativeVectorBase(heap)
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~ConservativeVector() = default;
|
||||
|
||||
ConservativeVector(ConservativeVector const& other)
|
||||
: ConservativeVectorBase(*other.m_heap)
|
||||
, Vector<T, inline_capacity>(other)
|
||||
{
|
||||
}
|
||||
|
||||
ConservativeVector(ConservativeVector&& other)
|
||||
: ConservativeVectorBase(*other.m_heap)
|
||||
, Vector<T, inline_capacity>(move(static_cast<Vector<T, inline_capacity>&>(other)))
|
||||
{
|
||||
}
|
||||
|
||||
ConservativeVector& operator=(ConservativeVector const& other)
|
||||
{
|
||||
Vector<T, inline_capacity>::operator=(other);
|
||||
ConservativeVectorBase::operator=(other);
|
||||
return *this;
|
||||
}
|
||||
|
||||
virtual ReadonlySpan<FlatPtr> possible_values() const override
|
||||
{
|
||||
static_assert(sizeof(T) >= sizeof(FlatPtr));
|
||||
return ReadonlySpan<FlatPtr> {
|
||||
reinterpret_cast<FlatPtr const*>(this->data()),
|
||||
this->size() * sizeof(T) / sizeof(FlatPtr),
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue