diff options
author | Andreas Kling <kling@serenityos.org> | 2022-10-16 16:42:39 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-10-20 15:16:23 +0200 |
commit | be5a39657ec56dbc11f82453c9c8f1665113bc79 (patch) | |
tree | 2fb0b8bb2c4d1a0d0230682e353e11abbac8c254 /Userland/Libraries/LibWeb/Layout | |
parent | 18a5c56f14f411edfe51a376f573d99438ace6ad (diff) | |
download | serenity-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).
Diffstat (limited to 'Userland/Libraries/LibWeb/Layout')
-rw-r--r-- | Userland/Libraries/LibWeb/Layout/Node.cpp | 22 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Layout/Node.h | 2 |
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 }; |