mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 03:57:43 +00:00
LibWeb: Only store one DOM pointer per Layout::Node
Instead of storing two JS::Handles into the DOM, we can combine them into a single one. If the layout node is anonymous, m_dom_node points to the DOM::Document. Otherwise, m_dom_node points to the associated DOM node. The anonymous state is moved to an m_anonymous boolean member. This cuts the number of JS::Handles created by the layout tree in half (and shrinks Layout::Node by 8 bytes).
This commit is contained in:
parent
18a5c56f14
commit
be5a39657e
2 changed files with 14 additions and 10 deletions
|
@ -20,18 +20,18 @@
|
|||
namespace Web::Layout {
|
||||
|
||||
Node::Node(DOM::Document& document, DOM::Node* node)
|
||||
: m_document(document)
|
||||
, m_dom_node(node)
|
||||
: m_dom_node(node ? node : &document)
|
||||
, m_anonymous(node == nullptr)
|
||||
{
|
||||
m_serial_id = m_document->next_layout_node_serial_id({});
|
||||
m_serial_id = document.next_layout_node_serial_id({});
|
||||
|
||||
if (m_dom_node)
|
||||
m_dom_node->set_layout_node({}, this);
|
||||
if (node)
|
||||
node->set_layout_node({}, this);
|
||||
}
|
||||
|
||||
Node::~Node()
|
||||
{
|
||||
if (m_dom_node && m_dom_node->layout_node() == this)
|
||||
if (!is_anonymous() && m_dom_node->layout_node() == this)
|
||||
m_dom_node->set_layout_node({}, nullptr);
|
||||
}
|
||||
|
||||
|
@ -625,27 +625,31 @@ RefPtr<Painting::Paintable> Node::create_paintable() const
|
|||
|
||||
bool Node::is_anonymous() const
|
||||
{
|
||||
return !m_dom_node.ptr();
|
||||
return m_anonymous;
|
||||
}
|
||||
|
||||
DOM::Node const* Node::dom_node() const
|
||||
{
|
||||
if (m_anonymous)
|
||||
return nullptr;
|
||||
return m_dom_node.ptr();
|
||||
}
|
||||
|
||||
DOM::Node* Node::dom_node()
|
||||
{
|
||||
if (m_anonymous)
|
||||
return nullptr;
|
||||
return m_dom_node.ptr();
|
||||
}
|
||||
|
||||
DOM::Document& Node::document()
|
||||
{
|
||||
return *m_document;
|
||||
return m_dom_node->document();
|
||||
}
|
||||
|
||||
DOM::Document const& Node::document() const
|
||||
{
|
||||
return *m_document;
|
||||
return m_dom_node->document();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue