1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 06:57:45 +00:00

LibWeb: Improve performance of CSS custom property resolution

By memoizing already resolved custom properties in the DOM::Element,
we achieve a notable speed increase when loading SerenityOS on GitHub.
This commit is contained in:
Tobias Christiansen 2021-05-28 21:21:44 +02:00 committed by Ali Mohammad Pur
parent 3ede1d08f5
commit 301eb998c6
3 changed files with 22 additions and 6 deletions

View file

@ -8,6 +8,8 @@
#include <AK/FlyString.h>
#include <AK/String.h>
#include <LibWeb/CSS/CSSStyleDeclaration.h>
#include <LibWeb/CSS/StyleResolver.h>
#include <LibWeb/DOM/Attribute.h>
#include <LibWeb/DOM/ExceptionOr.h>
#include <LibWeb/DOM/NonDocumentTypeChildNode.h>
@ -91,6 +93,15 @@ public:
const ShadowRoot* shadow_root() const { return m_shadow_root; }
void set_shadow_root(RefPtr<ShadowRoot>);
Optional<CSS::StyleResolver::CustomPropertyResolutionTuple> resolve_custom_property(const String& custom_property_name)
{
return m_custom_properties.get(custom_property_name);
}
void add_custom_property(const String& custom_property_name, CSS::StyleResolver::CustomPropertyResolutionTuple style_property)
{
m_custom_properties.set(custom_property_name, style_property);
}
protected:
RefPtr<Layout::Node> create_layout_node() override;
@ -107,6 +118,7 @@ private:
RefPtr<CSS::CSSStyleDeclaration> m_inline_style;
RefPtr<CSS::StyleProperties> m_specified_css_values;
HashMap<String, CSS::StyleResolver::CustomPropertyResolutionTuple> m_custom_properties;
Vector<FlyString> m_classes;