1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 20:18:12 +00:00

LibWeb: Cache lowercased names in SimpleSelector

When matching selectors in HTML documents, we know that all the elements
have lowercase local names already (the parser makes sure of this.)

Style sheets still need to remember the original name strings, in case
we want to match against non-HTML content like XML/SVG. To make the
common HTML case faster, we now cache a lowercase version of the name
with each type/class/id SimpleSelector.

This makes tag type checks O(1) instead of O(n).
This commit is contained in:
Andreas Kling 2022-09-15 13:51:30 +02:00
parent d9c64ee876
commit 1dd4e2dc87
4 changed files with 24 additions and 10 deletions

View file

@ -695,7 +695,7 @@ Parser::ParseErrorOr<Optional<Selector::SimpleSelector>> Parser::parse_simple_se
}
return Selector::SimpleSelector {
.type = Selector::SimpleSelector::Type::Class,
.value = FlyString { class_name_value.token().ident() }
.value = Selector::SimpleSelector::Name { class_name_value.token().ident() }
};
}
case '>':
@ -719,13 +719,13 @@ Parser::ParseErrorOr<Optional<Selector::SimpleSelector>> Parser::parse_simple_se
}
return Selector::SimpleSelector {
.type = Selector::SimpleSelector::Type::Id,
.value = FlyString { first_value.token().hash_value() }
.value = Selector::SimpleSelector::Name { first_value.token().hash_value() }
};
}
if (first_value.is(Token::Type::Ident)) {
return Selector::SimpleSelector {
.type = Selector::SimpleSelector::Type::TagName,
.value = FlyString { first_value.token().ident() }
.value = Selector::SimpleSelector::Name { first_value.token().ident() }
};
}
if (first_value.is_block() && first_value.block().is_square())