mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:47:34 +00:00
LibWeb: Parse CSS builtins before other values
These are straightforward to parse, so doing them first saves potentially expensive calculations inside parse_foo_value() functions.
This commit is contained in:
parent
aceea42ba4
commit
d2342caf42
2 changed files with 18 additions and 4 deletions
|
@ -1399,7 +1399,7 @@ Optional<float> Parser::try_parse_float(StringView string)
|
||||||
return is_negative ? -value : value;
|
return is_negative ? -value : value;
|
||||||
}
|
}
|
||||||
|
|
||||||
RefPtr<StyleValue> Parser::parse_builtin_or_dynamic_value(ParsingContext const& context, StyleComponentValueRule const& component_value)
|
RefPtr<StyleValue> Parser::parse_builtin_value(ParsingContext const&, StyleComponentValueRule const& component_value)
|
||||||
{
|
{
|
||||||
if (component_value.is(Token::Type::Ident)) {
|
if (component_value.is(Token::Type::Ident)) {
|
||||||
auto ident = component_value.token().ident();
|
auto ident = component_value.token().ident();
|
||||||
|
@ -1410,6 +1410,11 @@ RefPtr<StyleValue> Parser::parse_builtin_or_dynamic_value(ParsingContext const&
|
||||||
// FIXME: Implement `unset` keyword
|
// FIXME: Implement `unset` keyword
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
RefPtr<StyleValue> Parser::parse_dynamic_value(ParsingContext const& context, StyleComponentValueRule const& component_value)
|
||||||
|
{
|
||||||
if (component_value.is_function()) {
|
if (component_value.is_function()) {
|
||||||
auto& function = component_value.function();
|
auto& function = component_value.function();
|
||||||
|
|
||||||
|
@ -2766,6 +2771,11 @@ RefPtr<StyleValue> Parser::parse_css_value(PropertyID property_id, TokenStream<S
|
||||||
if (component_values.is_empty())
|
if (component_values.is_empty())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
|
if (component_values.size() == 1) {
|
||||||
|
if (auto parsed_value = parse_builtin_value(m_context, component_values.first()))
|
||||||
|
return parsed_value;
|
||||||
|
}
|
||||||
|
|
||||||
// Special-case property handling
|
// Special-case property handling
|
||||||
switch (property_id) {
|
switch (property_id) {
|
||||||
case PropertyID::Background:
|
case PropertyID::Background:
|
||||||
|
@ -2875,8 +2885,11 @@ RefPtr<StyleValue> Parser::parse_css_value(ParsingContext const& context, Proper
|
||||||
return LengthStyleValue::create(Length::make_px(strtof(string.characters(), nullptr)));
|
return LengthStyleValue::create(Length::make_px(strtof(string.characters(), nullptr)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (auto builtin_or_dynamic = parse_builtin_or_dynamic_value(context, component_value))
|
if (auto builtin = parse_builtin_value(context, component_value))
|
||||||
return builtin_or_dynamic;
|
return builtin;
|
||||||
|
|
||||||
|
if (auto dynamic = parse_dynamic_value(context, component_value))
|
||||||
|
return dynamic;
|
||||||
|
|
||||||
if (auto length = parse_length_value(context, component_value))
|
if (auto length = parse_length_value(context, component_value))
|
||||||
return length;
|
return length;
|
||||||
|
|
|
@ -168,7 +168,8 @@ private:
|
||||||
static Optional<Length> parse_length(ParsingContext const&, StyleComponentValueRule const&);
|
static Optional<Length> parse_length(ParsingContext const&, StyleComponentValueRule const&);
|
||||||
static Optional<URL> parse_url_function(ParsingContext const&, StyleComponentValueRule const&);
|
static Optional<URL> parse_url_function(ParsingContext const&, StyleComponentValueRule const&);
|
||||||
|
|
||||||
static RefPtr<StyleValue> parse_builtin_or_dynamic_value(ParsingContext const&, StyleComponentValueRule const&);
|
static RefPtr<StyleValue> parse_builtin_value(ParsingContext const&, StyleComponentValueRule const&);
|
||||||
|
static RefPtr<StyleValue> parse_dynamic_value(ParsingContext const&, StyleComponentValueRule const&);
|
||||||
static RefPtr<StyleValue> parse_length_value(ParsingContext const&, StyleComponentValueRule const&);
|
static RefPtr<StyleValue> parse_length_value(ParsingContext const&, StyleComponentValueRule const&);
|
||||||
static RefPtr<StyleValue> parse_numeric_value(ParsingContext const&, StyleComponentValueRule const&);
|
static RefPtr<StyleValue> parse_numeric_value(ParsingContext const&, StyleComponentValueRule const&);
|
||||||
static RefPtr<StyleValue> parse_identifier_value(ParsingContext const&, StyleComponentValueRule const&);
|
static RefPtr<StyleValue> parse_identifier_value(ParsingContext const&, StyleComponentValueRule const&);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue