From 733ad57f39fe9fcad3d21ccf803027661160e1da Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Mon, 4 Sep 2023 10:50:42 +0100 Subject: [PATCH] LibWeb: Expose Parser::Function name as FlyString const& This saves us from having to re-convert the StringView back to a FlyString again when resolving UnresolvedStyleValues. --- Userland/Libraries/LibWeb/CSS/Parser/Function.h | 2 +- Userland/Libraries/LibWeb/CSS/Parser/GradientParsing.cpp | 6 +++--- Userland/Libraries/LibWeb/CSS/StyleComputer.cpp | 3 +-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Function.h b/Userland/Libraries/LibWeb/CSS/Parser/Function.h index f078f5de0c9..81c3f7d9162 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Function.h +++ b/Userland/Libraries/LibWeb/CSS/Parser/Function.h @@ -25,7 +25,7 @@ public: ~Function(); - StringView name() const { return m_name; } + FlyString const& name() const { return m_name; } Vector const& values() const { return m_values; } String to_string() const; diff --git a/Userland/Libraries/LibWeb/CSS/Parser/GradientParsing.cpp b/Userland/Libraries/LibWeb/CSS/Parser/GradientParsing.cpp index 2b01c7da740..0539e3fa263 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/GradientParsing.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/GradientParsing.cpp @@ -150,7 +150,7 @@ RefPtr Parser::parse_linear_gradient_function(ComponentValue const& GradientRepeating repeating_gradient = GradientRepeating::No; GradientType gradient_type { GradientType::Standard }; - auto function_name = component_value.function().name(); + auto function_name = component_value.function().name().bytes_as_string_view(); function_name = consume_if_starts_with(function_name, "-webkit-"sv, [&] { gradient_type = GradientType::WebKit; @@ -275,7 +275,7 @@ RefPtr Parser::parse_conic_gradient_function(ComponentValue const& c GradientRepeating repeating_gradient = GradientRepeating::No; - auto function_name = component_value.function().name(); + auto function_name = component_value.function().name().bytes_as_string_view(); function_name = consume_if_starts_with(function_name, "repeating-"sv, [&] { repeating_gradient = GradientRepeating::Yes; @@ -378,7 +378,7 @@ RefPtr Parser::parse_radial_gradient_function(ComponentValue const& auto repeating_gradient = GradientRepeating::No; - auto function_name = component_value.function().name(); + auto function_name = component_value.function().name().bytes_as_string_view(); function_name = consume_if_starts_with(function_name, "repeating-"sv, [&] { repeating_gradient = GradientRepeating::Yes; diff --git a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp index 2ac2ccebb5a..e52af875c4d 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp @@ -1140,8 +1140,7 @@ bool StyleComputer::expand_unresolved_values(DOM::Element& element, StringView p Parser::TokenStream source_function_contents { source_function.values() }; if (!expand_unresolved_values(element, property_name, source_function_contents, function_values)) return false; - // FIXME: This would be much nicer if we could access the source_function's FlyString value directly. - NonnullRefPtr function = Parser::Function::create(FlyString::from_utf8(source_function.name()).release_value_but_fixme_should_propagate_errors(), move(function_values)); + NonnullRefPtr function = Parser::Function::create(source_function.name(), move(function_values)); dest.empend(function); continue; }