LibWeb: Make Node::is_connected() O(1) via a cached flag

Previously this walked up the parent chain on every call, which shows
up as a 2.5% item in the profile while watching YouTube videos.

Cache an m_is_connected bit on Node instead, maintained by the DOM
insertion and removal steps.
This commit is contained in:
Andreas Kling 2026-04-15 23:56:07 +02:00 committed by Andreas Kling
parent c3fb1be321
commit e330d5b9ab
Notes: github-actions[bot] 2026-04-16 06:27:33 +00:00
5 changed files with 25 additions and 14 deletions

View file

@ -42,14 +42,14 @@ void HTMLStyleElement::children_changed(ChildrenChangedMetadata const& metadata)
void HTMLStyleElement::inserted()
{
update_a_style_block();
Base::inserted();
update_a_style_block();
}
void HTMLStyleElement::removed_from(Node* old_parent, Node& old_root)
{
update_a_style_block();
Base::removed_from(old_parent, old_root);
update_a_style_block();
}
void HTMLStyleElement::attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value, Optional<FlyString> const& namespace_)