From 74b6e7b1f0b10aac41ddabfd668f19a39bdaaf18 Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Sun, 10 Dec 2023 16:18:26 +1300 Subject: [PATCH] LibWeb: Avoid calling FlyString::from_utf8 on FlyString's --- .../Libraries/LibWeb/CSS/Parser/Parser.cpp | 18 +++++++++--------- .../LibWeb/CSS/Parser/SelectorParsing.cpp | 18 +++++++++--------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp index 4239e0d6dd..099d0eca3d 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -421,7 +421,7 @@ NonnullRefPtr Parser::consume_an_at_rule(TokenStream& tokens) // Create a new at-rule with its name set to the value of the current input token, its prelude initially set to an empty list, and its value initially set to nothing. // NOTE: We create the Rule fully initialized when we return it instead. - auto at_rule_name = FlyString::from_utf8(((Token)name_ident).at_keyword()).release_value_but_fixme_should_propagate_errors(); + auto at_rule_name = ((Token)name_ident).at_keyword(); Vector prelude; RefPtr block; @@ -704,7 +704,7 @@ NonnullRefPtr Parser::consume_a_function(TokenStream& tokens) // Create a function with its name equal to the value of the current input token // and with its value initially set to an empty list. // NOTE: We create the Function fully initialized when we return it instead. - auto function_name = FlyString::from_utf8(((Token)name_ident).function()).release_value_but_fixme_should_propagate_errors(); + auto function_name = ((Token)name_ident).function(); Vector function_values; // Repeatedly consume the next input token and process it as follows: @@ -759,7 +759,7 @@ Optional Parser::consume_a_declaration(TokenStream& tokens) // Create a new declaration with its name set to the value of the current input token // and its value initially set to the empty list. // NOTE: We create a fully-initialized Declaration just before returning it instead. - auto declaration_name = FlyString::from_utf8(((Token)token).ident()).release_value_but_fixme_should_propagate_errors(); + auto declaration_name = ((Token)token).ident(); Vector declaration_values; Important declaration_important = Important::No; @@ -6064,7 +6064,7 @@ Optional Parser::parse_css_value_for_properties(Readon // Custom idents if (auto property = any_property_accepts_type(property_ids, ValueType::CustomIdent); property.has_value()) { (void)tokens.next_token(); - return PropertyAndValue { *property, CustomIdentStyleValue::create(MUST(FlyString::from_utf8(peek_token.token().ident()))) }; + return PropertyAndValue { *property, CustomIdentStyleValue::create(peek_token.token().ident()) }; } } @@ -6726,7 +6726,7 @@ bool Parser::expand_variables(DOM::Element& element, Optional function = Function::create(FlyString::from_utf8(source_function.name()).release_value_but_fixme_should_propagate_errors(), move(function_values)); + NonnullRefPtr function = Function::create(source_function.name(), move(function_values)); dest.empend(function); continue; } @@ -6748,13 +6748,13 @@ bool Parser::expand_variables(DOM::Element& element, Optionaladd_child(child); if (parent->has_cycles()) return false; - if (auto custom_property_value = get_custom_property(element, pseudo_element, FlyString::from_utf8(custom_property_name).release_value_but_fixme_should_propagate_errors())) { + if (auto custom_property_value = get_custom_property(element, pseudo_element, custom_property_name)) { VERIFY(custom_property_value->is_unresolved()); TokenStream custom_property_tokens { custom_property_value->as_unresolved().values() }; if (!expand_variables(element, pseudo_element, custom_property_name, dependencies, custom_property_tokens, dest)) @@ -6867,7 +6867,7 @@ bool Parser::substitute_attr_function(DOM::Element& element, StringView property // - Attribute type (optional) auto attribute_type = "string"_fly_string; if (attr_contents.peek_token().is(Token::Type::Ident)) { - attribute_type = MUST(FlyString::from_utf8(attr_contents.next_token().token().ident())); + attribute_type = attr_contents.next_token().token().ident(); attr_contents.skip_whitespace(); } diff --git a/Userland/Libraries/LibWeb/CSS/Parser/SelectorParsing.cpp b/Userland/Libraries/LibWeb/CSS/Parser/SelectorParsing.cpp index 0bdd239aea..162f20dc70 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/SelectorParsing.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/SelectorParsing.cpp @@ -142,8 +142,8 @@ Optional Parser::parse_selector_qualifi }; auto get_name = [](ComponentValue const& token) { if (token.is_delim('*')) - return FlyString::from_utf8("*"sv); - return FlyString::from_utf8(token.token().ident()); + return "*"_fly_string; + return token.token().ident(); }; // There are 3 possibilities here: @@ -167,7 +167,7 @@ Optional Parser::parse_selector_qualifi transaction.commit(); return Selector::SimpleSelector::QualifiedName { .namespace_type = Selector::SimpleSelector::QualifiedName::NamespaceType::None, - .name = get_name(name_token).release_value_but_fixme_should_propagate_errors(), + .name = get_name(name_token), }; } return {}; @@ -179,8 +179,8 @@ Optional Parser::parse_selector_qualifi if (tokens.peek_token().is_delim('|') && is_name(tokens.peek_token(1))) { // Case 2: `|` (void)tokens.next_token(); // `|` - auto namespace_ = get_name(first_token).release_value_but_fixme_should_propagate_errors(); - auto name = get_name(tokens.next_token()).release_value_but_fixme_should_propagate_errors(); + auto namespace_ = get_name(first_token); + auto name = get_name(tokens.next_token()); if (allow_wildcard_name == AllowWildcardName::No && name == "*"sv) return {}; @@ -205,7 +205,7 @@ Optional Parser::parse_selector_qualifi transaction.commit(); return Selector::SimpleSelector::QualifiedName { .namespace_type = Selector::SimpleSelector::QualifiedName::NamespaceType::Default, - .name = get_name(name_token).release_value_but_fixme_should_propagate_errors(), + .name = get_name(name_token), }; } @@ -550,7 +550,7 @@ Parser::ParseErrorOr Parser::parse_pseudo_simple_selec } auto language_string = language_token.is(Token::Type::String) ? language_token.token().string() : language_token.token().ident(); - languages.append(MUST(FlyString::from_utf8(language_string))); + languages.append(language_string); language_token_stream.skip_whitespace(); if (language_token_stream.has_next_token()) { @@ -629,7 +629,7 @@ Parser::ParseErrorOr> Parser::parse_simple_se } return Selector::SimpleSelector { .type = Selector::SimpleSelector::Type::Class, - .value = Selector::SimpleSelector::Name { FlyString::from_utf8(class_name_value.token().ident()).release_value_but_fixme_should_propagate_errors() } + .value = Selector::SimpleSelector::Name { class_name_value.token().ident() } }; } case '>': @@ -653,7 +653,7 @@ Parser::ParseErrorOr> Parser::parse_simple_se } return Selector::SimpleSelector { .type = Selector::SimpleSelector::Type::Id, - .value = Selector::SimpleSelector::Name { FlyString::from_utf8(first_value.token().hash_value()).release_value_but_fixme_should_propagate_errors() } + .value = Selector::SimpleSelector::Name { first_value.token().hash_value() } }; }