1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 06:37:43 +00:00

LibWeb: Cache pseudo element layout nodes weakly on DOM::Element

Having the cache be strong created a reference cycle between DOM nodes
and their pseudo elements.
This commit is contained in:
Andreas Kling 2022-10-16 18:23:02 +02:00
parent e23fe8cf87
commit 8412206cb4
2 changed files with 4 additions and 4 deletions

View file

@ -711,17 +711,17 @@ void Element::children_changed()
void Element::set_pseudo_element_node(Badge<Layout::TreeBuilder>, CSS::Selector::PseudoElement pseudo_element, RefPtr<Layout::Node> pseudo_element_node) void Element::set_pseudo_element_node(Badge<Layout::TreeBuilder>, CSS::Selector::PseudoElement pseudo_element, RefPtr<Layout::Node> pseudo_element_node)
{ {
m_pseudo_element_nodes[to_underlying(pseudo_element)] = move(pseudo_element_node); m_pseudo_element_nodes[to_underlying(pseudo_element)] = pseudo_element_node->make_weak_ptr();
} }
RefPtr<Layout::Node> Element::get_pseudo_element_node(CSS::Selector::PseudoElement pseudo_element) const RefPtr<Layout::Node> Element::get_pseudo_element_node(CSS::Selector::PseudoElement pseudo_element) const
{ {
return m_pseudo_element_nodes[to_underlying(pseudo_element)]; return m_pseudo_element_nodes[to_underlying(pseudo_element)].strong_ref();
} }
void Element::clear_pseudo_element_nodes(Badge<Layout::TreeBuilder>) void Element::clear_pseudo_element_nodes(Badge<Layout::TreeBuilder>)
{ {
m_pseudo_element_nodes.fill(nullptr); m_pseudo_element_nodes.fill({});
} }
void Element::serialize_pseudo_elements_as_json(JsonArraySerializer<StringBuilder>& children_array) const void Element::serialize_pseudo_elements_as_json(JsonArraySerializer<StringBuilder>& children_array) const

View file

@ -188,7 +188,7 @@ private:
Vector<FlyString> m_classes; Vector<FlyString> m_classes;
Array<RefPtr<Layout::Node>, CSS::Selector::PseudoElementCount> m_pseudo_element_nodes; Array<WeakPtr<Layout::Node>, CSS::Selector::PseudoElementCount> m_pseudo_element_nodes;
}; };
template<> template<>