فهرست منبع

LibWeb: Allocate storage for pseudo element custom properties on demand

Most elements don't have pseudo elements with CSS custom properties.
By only allocating this data structure when it's used, we can shrink
most elements by 208 bytes each. :^)
Andreas Kling 1 سال پیش
والد
کامیت
37505d9746
2فایلهای تغییر یافته به همراه13 افزوده شده و 3 حذف شده
  1. 9 2
      Userland/Libraries/LibWeb/DOM/Element.cpp
  2. 4 1
      Userland/Libraries/LibWeb/DOM/Element.h

+ 9 - 2
Userland/Libraries/LibWeb/DOM/Element.cpp

@@ -2050,20 +2050,27 @@ void Element::set_computed_css_values(RefPtr<CSS::StyleProperties> style)
     m_computed_css_values = move(style);
 }
 
+auto Element::pseudo_element_custom_properties() const -> PseudoElementCustomProperties&
+{
+    if (!m_pseudo_element_custom_properties)
+        m_pseudo_element_custom_properties = make<PseudoElementCustomProperties>();
+    return *m_pseudo_element_custom_properties;
+}
+
 void Element::set_custom_properties(Optional<CSS::Selector::PseudoElement> pseudo_element, HashMap<FlyString, CSS::StyleProperty> custom_properties)
 {
     if (!pseudo_element.has_value()) {
         m_custom_properties = move(custom_properties);
         return;
     }
-    m_pseudo_element_custom_properties[to_underlying(pseudo_element.value())] = move(custom_properties);
+    pseudo_element_custom_properties()[to_underlying(pseudo_element.value())] = move(custom_properties);
 }
 
 HashMap<FlyString, CSS::StyleProperty> const& Element::custom_properties(Optional<CSS::Selector::PseudoElement> pseudo_element) const
 {
     if (!pseudo_element.has_value())
         return m_custom_properties;
-    return m_pseudo_element_custom_properties[to_underlying(pseudo_element.value())];
+    return pseudo_element_custom_properties()[to_underlying(pseudo_element.value())];
 }
 
 // https://drafts.csswg.org/cssom-view/#dom-element-scroll

+ 4 - 1
Userland/Libraries/LibWeb/DOM/Element.h

@@ -402,7 +402,10 @@ private:
 
     RefPtr<CSS::StyleProperties> m_computed_css_values;
     HashMap<FlyString, CSS::StyleProperty> m_custom_properties;
-    Array<HashMap<FlyString, CSS::StyleProperty>, to_underlying(CSS::Selector::PseudoElement::PseudoElementCount)> m_pseudo_element_custom_properties;
+
+    using PseudoElementCustomProperties = Array<HashMap<FlyString, CSS::StyleProperty>, to_underlying(CSS::Selector::PseudoElement::PseudoElementCount)>;
+    mutable OwnPtr<PseudoElementCustomProperties> m_pseudo_element_custom_properties;
+    PseudoElementCustomProperties& pseudo_element_custom_properties() const;
 
     Vector<FlyString> m_classes;
     Optional<Dir> m_dir;