Преглед на файлове

LibWeb: Avoid copying the CSS @namespace every time we run a selector

Andreas Kling преди 1 година
родител
ревизия
038e0ceee7
променени са 2 файла, в които са добавени 5 реда и са изтрити 3 реда
  1. 2 0
      Userland/Libraries/LibWeb/CSS/CSSStyleSheet.h
  2. 3 3
      Userland/Libraries/LibWeb/CSS/StyleComputer.cpp

+ 2 - 0
Userland/Libraries/LibWeb/CSS/CSSStyleSheet.h

@@ -65,6 +65,8 @@ public:
     void set_style_sheet_list(Badge<StyleSheetList>, StyleSheetList*);
 
     Optional<FlyString> default_namespace() const;
+    JS::GCPtr<CSSNamespaceRule> default_namespace_rule() const { return m_default_namespace_rule; }
+
     Optional<FlyString> namespace_uri(StringView namespace_prefix) const;
 
     Optional<URL> base_url() const { return m_base_url; }

+ 3 - 3
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;
 }