summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2022-10-16 16:42:39 +0200
committerAndreas Kling <kling@serenityos.org>2022-10-20 15:16:23 +0200
commitbe5a39657ec56dbc11f82453c9c8f1665113bc79 (patch)
tree2fb0b8bb2c4d1a0d0230682e353e11abbac8c254
parent18a5c56f14f411edfe51a376f573d99438ace6ad (diff)
downloadserenity-be5a39657ec56dbc11f82453c9c8f1665113bc79.zip
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).
-rw-r--r--Userland/Libraries/LibWeb/Layout/Node.cpp22
-rw-r--r--Userland/Libraries/LibWeb/Layout/Node.h2
2 files changed, 14 insertions, 10 deletions
diff --git a/Userland/Libraries/LibWeb/Layout/Node.cpp b/Userland/Libraries/LibWeb/Layout/Node.cpp
index bcca562761..4a0838af27 100644
--- a/Userland/Libraries/LibWeb/Layout/Node.cpp
+++ b/Userland/Libraries/LibWeb/Layout/Node.cpp
@@ -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();
}
}
diff --git a/Userland/Libraries/LibWeb/Layout/Node.h b/Userland/Libraries/LibWeb/Layout/Node.h
index 3a7b9db406..e8ca0bfe1b 100644
--- a/Userland/Libraries/LibWeb/Layout/Node.h
+++ b/Userland/Libraries/LibWeb/Layout/Node.h
@@ -143,12 +143,12 @@ protected:
private:
friend class NodeWithStyle;
- JS::Handle<DOM::Document> m_document;
JS::Handle<DOM::Node> m_dom_node;
RefPtr<Painting::Paintable> m_paintable;
size_t m_serial_id { 0 };
+ bool m_anonymous { false };
bool m_has_style { false };
bool m_visible { true };
bool m_children_are_inline { false };