mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-02 06:09:08 +00:00
LibWeb: Make CSSStyleRule::qualified_layer_name() return a const-ref
And also make it inline. We were spending 8% of selector matching on creating and destroying FlyString copies here. With this change, it's now ~1%.
This commit is contained in:
parent
ef4f5ac8fb
commit
b2aff403fc
Notes:
github-actions[bot]
2024-09-09 18:13:00 +00:00
Author: https://github.com/awesomekling
Commit: b2aff403fc
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1345
4 changed files with 34 additions and 34 deletions
|
@ -48,38 +48,36 @@ void CSSRule::set_parent_style_sheet(CSSStyleSheet* parent_style_sheet)
|
||||||
m_parent_style_sheet = parent_style_sheet;
|
m_parent_style_sheet = parent_style_sheet;
|
||||||
}
|
}
|
||||||
|
|
||||||
FlyString const& CSSRule::parent_layer_internal_qualified_name() const
|
FlyString const& CSSRule::parent_layer_internal_qualified_name_slow_case() const
|
||||||
{
|
{
|
||||||
if (!m_cached_layer_name.has_value()) {
|
Vector<FlyString> layer_names;
|
||||||
Vector<FlyString> layer_names;
|
for (auto* rule = parent_rule(); rule; rule = rule->parent_rule()) {
|
||||||
for (auto* rule = parent_rule(); rule; rule = rule->parent_rule()) {
|
switch (rule->type()) {
|
||||||
switch (rule->type()) {
|
case CSSRule::Type::Import:
|
||||||
case CSSRule::Type::Import:
|
// TODO: Handle `layer(foo)` in import rules once we implement that.
|
||||||
// TODO: Handle `layer(foo)` in import rules once we implement that.
|
break;
|
||||||
break;
|
|
||||||
|
|
||||||
case CSSRule::Type::LayerBlock: {
|
case CSSRule::Type::LayerBlock: {
|
||||||
auto& layer_block = static_cast<CSSLayerBlockRule const&>(*rule);
|
auto& layer_block = static_cast<CSSLayerBlockRule const&>(*rule);
|
||||||
layer_names.append(layer_block.internal_name());
|
layer_names.append(layer_block.internal_name());
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
// Ignore everything else
|
|
||||||
// Note that LayerStatement cannot have child rules so we still ignore it here.
|
|
||||||
case CSSRule::Type::LayerStatement:
|
|
||||||
case CSSRule::Type::Style:
|
|
||||||
case CSSRule::Type::Media:
|
|
||||||
case CSSRule::Type::FontFace:
|
|
||||||
case CSSRule::Type::Keyframes:
|
|
||||||
case CSSRule::Type::Keyframe:
|
|
||||||
case CSSRule::Type::Namespace:
|
|
||||||
case CSSRule::Type::Supports:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_cached_layer_name = MUST(String::join("."sv, layer_names.in_reverse()));
|
// Ignore everything else
|
||||||
|
// Note that LayerStatement cannot have child rules so we still ignore it here.
|
||||||
|
case CSSRule::Type::LayerStatement:
|
||||||
|
case CSSRule::Type::Style:
|
||||||
|
case CSSRule::Type::Media:
|
||||||
|
case CSSRule::Type::FontFace:
|
||||||
|
case CSSRule::Type::Keyframes:
|
||||||
|
case CSSRule::Type::Keyframe:
|
||||||
|
case CSSRule::Type::Namespace:
|
||||||
|
case CSSRule::Type::Supports:
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_cached_layer_name = MUST(String::join("."sv, layer_names.in_reverse()));
|
||||||
return m_cached_layer_name.value();
|
return m_cached_layer_name.value();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,7 +58,14 @@ protected:
|
||||||
|
|
||||||
virtual void visit_edges(Cell::Visitor&) override;
|
virtual void visit_edges(Cell::Visitor&) override;
|
||||||
|
|
||||||
FlyString const& parent_layer_internal_qualified_name() const;
|
[[nodiscard]] FlyString const& parent_layer_internal_qualified_name() const
|
||||||
|
{
|
||||||
|
if (!m_cached_layer_name.has_value())
|
||||||
|
return parent_layer_internal_qualified_name_slow_case();
|
||||||
|
return m_cached_layer_name.value();
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] FlyString const& parent_layer_internal_qualified_name_slow_case() const;
|
||||||
|
|
||||||
JS::GCPtr<CSSRule> m_parent_rule;
|
JS::GCPtr<CSSRule> m_parent_rule;
|
||||||
JS::GCPtr<CSSStyleSheet> m_parent_style_sheet;
|
JS::GCPtr<CSSStyleSheet> m_parent_style_sheet;
|
||||||
|
|
|
@ -46,11 +46,6 @@ CSSStyleDeclaration* CSSStyleRule::style()
|
||||||
return m_declaration;
|
return m_declaration;
|
||||||
}
|
}
|
||||||
|
|
||||||
FlyString CSSStyleRule::qualified_layer_name() const
|
|
||||||
{
|
|
||||||
return parent_layer_internal_qualified_name();
|
|
||||||
}
|
|
||||||
|
|
||||||
// https://www.w3.org/TR/cssom/#serialize-a-css-rule
|
// https://www.w3.org/TR/cssom/#serialize-a-css-rule
|
||||||
String CSSStyleRule::serialized() const
|
String CSSStyleRule::serialized() const
|
||||||
{
|
{
|
||||||
|
|
|
@ -33,7 +33,7 @@ public:
|
||||||
|
|
||||||
CSSStyleDeclaration* style();
|
CSSStyleDeclaration* style();
|
||||||
|
|
||||||
FlyString qualified_layer_name() const;
|
[[nodiscard]] FlyString const& qualified_layer_name() const { return parent_layer_internal_qualified_name(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CSSStyleRule(JS::Realm&, Vector<NonnullRefPtr<Selector>>&&, PropertyOwningCSSStyleDeclaration&);
|
CSSStyleRule(JS::Realm&, Vector<NonnullRefPtr<Selector>>&&, PropertyOwningCSSStyleDeclaration&);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue