From ccb543ebb8331449589a2e4e90f69afcec19eed5 Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Thu, 2 Jan 2025 21:07:47 +0300 Subject: [PATCH] LibWeb/CSS: Skip build of rule cache for inactive documents Some websites (Reddit, for example) create lots of temporary documents for fragment parsing. Before this change, we had to build a rule cache for these documents just to determine whether there are :has, :defined, or attribute selectors, while it should be safe to simply return `false` right away. --- Libraries/LibWeb/CSS/StyleComputer.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Libraries/LibWeb/CSS/StyleComputer.cpp b/Libraries/LibWeb/CSS/StyleComputer.cpp index 1d168e7a052..1b13a4e0684 100644 --- a/Libraries/LibWeb/CSS/StyleComputer.cpp +++ b/Libraries/LibWeb/CSS/StyleComputer.cpp @@ -3017,20 +3017,28 @@ size_t StyleComputer::number_of_css_font_faces_with_loading_in_progress() const bool StyleComputer::has_has_selectors() const { + if (!document().is_active()) + return false; + build_rule_cache_if_needed(); return m_selector_insights->has_has_selectors; } bool StyleComputer::has_defined_selectors() const { + if (!document().is_active()) + return false; + build_rule_cache_if_needed(); return m_selector_insights->has_defined_selectors; } bool StyleComputer::has_attribute_selector(FlyString const& attribute_name) const { - build_rule_cache_if_needed(); + if (!document().is_active()) + return false; + build_rule_cache_if_needed(); return m_selector_insights->all_names_used_in_attribute_selectors.contains(attribute_name); }