mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 20:15:17 +00:00
LibWeb: Avoid calling Element::is_shadow_host() for each CSS rule
Instead just cache the element's shadow root locally, if any. This shaves ~1 second off the loading time of https://wpt.fyi/
This commit is contained in:
parent
e03aedbdf0
commit
801b3f434f
Notes:
github-actions[bot]
2025-01-26 14:08:27 +00:00
Author: https://github.com/awesomekling Commit: https://github.com/LadybirdBrowser/ladybird/commit/801b3f434ff Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3370 Reviewed-by: https://github.com/gmta ✅
1 changed files with 3 additions and 2 deletions
|
@ -471,9 +471,10 @@ Vector<MatchingRule const*> StyleComputer::collect_matching_rules(DOM::Element c
|
|||
{
|
||||
auto const& root_node = element.root();
|
||||
auto shadow_root = is<DOM::ShadowRoot>(root_node) ? static_cast<DOM::ShadowRoot const*>(&root_node) : nullptr;
|
||||
auto element_shadow_root = element.shadow_root();
|
||||
|
||||
GC::Ptr<DOM::Element const> shadow_host;
|
||||
if (element.is_shadow_host())
|
||||
if (element_shadow_root)
|
||||
shadow_host = element;
|
||||
else if (shadow_root)
|
||||
shadow_host = shadow_root->host();
|
||||
|
@ -497,7 +498,7 @@ Vector<MatchingRule const*> StyleComputer::collect_matching_rules(DOM::Element c
|
|||
// but instead we'd have some kind of "style scope" at the document level, and also one for each shadow root.
|
||||
// Then we could only evaluate rules from the current style scope.
|
||||
bool rule_is_relevant_for_current_scope = rule_root == shadow_root
|
||||
|| (element.is_shadow_host() && rule_root == element.shadow_root())
|
||||
|| (element_shadow_root && rule_root == element_shadow_root)
|
||||
|| from_user_agent_or_user_stylesheet;
|
||||
|
||||
if (!rule_is_relevant_for_current_scope)
|
||||
|
|
Loading…
Add table
Reference in a new issue