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:
Andreas Kling 2024-09-09 17:35:13 +02:00 committed by Andreas Kling
commit b2aff403fc
Notes: github-actions[bot] 2024-09-09 18:13:00 +00:00
4 changed files with 34 additions and 34 deletions

View file

@ -48,38 +48,36 @@ void CSSRule::set_parent_style_sheet(CSSStyleSheet* 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;
for (auto* rule = parent_rule(); rule; rule = rule->parent_rule()) {
switch (rule->type()) {
case CSSRule::Type::Import:
// TODO: Handle `layer(foo)` in import rules once we implement that.
break;
Vector<FlyString> layer_names;
for (auto* rule = parent_rule(); rule; rule = rule->parent_rule()) {
switch (rule->type()) {
case CSSRule::Type::Import:
// TODO: Handle `layer(foo)` in import rules once we implement that.
break;
case CSSRule::Type::LayerBlock: {
auto& layer_block = static_cast<CSSLayerBlockRule const&>(*rule);
layer_names.append(layer_block.internal_name());
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;
}
case CSSRule::Type::LayerBlock: {
auto& layer_block = static_cast<CSSLayerBlockRule const&>(*rule);
layer_names.append(layer_block.internal_name());
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();
}