From 038e0ceee7497bb12c08d00cd21dea762fbdb1ed Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 16 Mar 2024 08:03:46 +0100 Subject: [PATCH] LibWeb: Avoid copying the CSS @namespace every time we run a selector --- Userland/Libraries/LibWeb/CSS/CSSStyleSheet.h | 2 ++ Userland/Libraries/LibWeb/CSS/StyleComputer.cpp | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Userland/Libraries/LibWeb/CSS/CSSStyleSheet.h b/Userland/Libraries/LibWeb/CSS/CSSStyleSheet.h index 46e1ce4aca8..fc102319eaa 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSStyleSheet.h +++ b/Userland/Libraries/LibWeb/CSS/CSSStyleSheet.h @@ -65,6 +65,8 @@ public: void set_style_sheet_list(Badge, StyleSheetList*); Optional default_namespace() const; + JS::GCPtr default_namespace_rule() const { return m_default_namespace_rule; } + Optional namespace_uri(StringView namespace_prefix) const; Optional base_url() const { return m_base_url; } diff --git a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp index de570b6c85f..d38b4b855d3 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp @@ -295,9 +295,9 @@ StyleComputer::RuleCache const& StyleComputer::rule_cache_for_cascade_origin(Cas [[nodiscard]] static bool filter_namespace_rule(DOM::Element const& element, MatchingRule const& rule) { // FIXME: Filter out non-default namespace using prefixes - auto namespace_uri = rule.sheet->default_namespace(); - if (namespace_uri.has_value() && namespace_uri.value() != element.namespace_uri()) { - return false; + if (auto namespace_rule = rule.sheet->default_namespace_rule()) { + if (namespace_rule->namespace_uri() != element.namespace_uri()) + return false; } return true; }