From 6da7a6eab541e4c6068b35ca167cce69046489a9 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Wed, 5 Feb 2025 17:48:58 +0000 Subject: [PATCH] LibWeb/CSS: Un-template some CSS Parser methods A few of these are only ever called with T=Token, so let's simplify them a bit. As a drive-by change: Also correct the "unnecessairy" typos and use discard_a_token(). --- Libraries/LibWeb/CSS/Parser/Parser.cpp | 42 +++++++++----------------- 1 file changed, 14 insertions(+), 28 deletions(-) diff --git a/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Libraries/LibWeb/CSS/Parser/Parser.cpp index eb9cdcb256a..a85ca7d2982 100644 --- a/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -633,8 +633,8 @@ ComponentValue Parser::consume_a_component_value(TokenStream -ComponentValue Parser::consume_a_component_value(TokenStream& input) +template<> +ComponentValue Parser::consume_a_component_value(TokenStream& input) { // To consume a component value from a token stream input: @@ -667,18 +667,18 @@ ComponentValue Parser::consume_a_component_value(TokenStream& input) template<> void Parser::consume_a_component_value_and_do_nothing(TokenStream& tokens) { - // AD-HOC: To avoid unnecessairy allocations, we explicitly define a "do nothing" variant that discards the result immediately. + // AD-HOC: To avoid unnecessary allocations, we explicitly define a "do nothing" variant that discards the result immediately. // Note: This overload is called once tokens have already been converted into component values, // so we do not need to do the work in the more general overload. - (void)tokens.consume_a_token(); + tokens.discard_a_token(); } // 5.4.7. Consume a component value // https://drafts.csswg.org/css-syntax/#consume-component-value -template -void Parser::consume_a_component_value_and_do_nothing(TokenStream& input) +template<> +void Parser::consume_a_component_value_and_do_nothing(TokenStream& input) { - // AD-HOC: To avoid unnecessairy allocations, we explicitly define a "do nothing" variant that discards the result immediately. + // AD-HOC: To avoid unnecessary allocations, we explicitly define a "do nothing" variant that discards the result immediately. // To consume a component value from a token stream input: // Process input: @@ -752,8 +752,7 @@ Vector Parser::consume_a_list_of_component_values(TokenStream } // https://drafts.csswg.org/css-syntax/#consume-simple-block -template -SimpleBlock Parser::consume_a_simple_block(TokenStream& input) +SimpleBlock Parser::consume_a_simple_block(TokenStream& input) { // To consume a simple block from a token stream input: @@ -789,16 +788,15 @@ SimpleBlock Parser::consume_a_simple_block(TokenStream& input) // anything else { // Consume a component value from input and append the result to block’s value. - block.value.empend(move(consume_a_component_value(input))); + block.value.append(consume_a_component_value(input)); } } } // https://drafts.csswg.org/css-syntax/#consume-simple-block -template -void Parser::consume_a_simple_block_and_do_nothing(TokenStream& input) +void Parser::consume_a_simple_block_and_do_nothing(TokenStream& input) { - // AD-HOC: To avoid unnecessairy allocations, we explicitly define a "do nothing" variant that discards the result immediately. + // AD-HOC: To avoid unnecessary allocations, we explicitly define a "do nothing" variant that discards the result immediately. // To consume a simple block from a token stream input: // Assert: the next token of input is <{-token>, <[-token>, or <(-token>. @@ -834,8 +832,7 @@ void Parser::consume_a_simple_block_and_do_nothing(TokenStream& input) } // https://drafts.csswg.org/css-syntax/#consume-function -template -Function Parser::consume_a_function(TokenStream& input) +Function Parser::consume_a_function(TokenStream& input) { // To consume a function from a token stream input: @@ -873,10 +870,9 @@ Function Parser::consume_a_function(TokenStream& input) } // https://drafts.csswg.org/css-syntax/#consume-function -template -void Parser::consume_a_function_and_do_nothing(TokenStream& input) +void Parser::consume_a_function_and_do_nothing(TokenStream& input) { - // AD-HOC: To avoid unnecessairy allocations, we explicitly define a "do nothing" variant that discards the result immediately. + // AD-HOC: To avoid unnecessary allocations, we explicitly define a "do nothing" variant that discards the result immediately. // To consume a function from a token stream input: // Assert: The next token is a . @@ -1703,16 +1699,6 @@ template Vector Parser::consume_a_blocks_contents(Toke template Vector Parser::consume_a_list_of_component_values(TokenStream&, Optional, Nested); template Vector Parser::consume_a_list_of_component_values(TokenStream&, Optional, Nested); -template SimpleBlock Parser::consume_a_simple_block(TokenStream&); - -template void Parser::consume_a_simple_block_and_do_nothing(TokenStream&); - -template Function Parser::consume_a_function(TokenStream&); -template Function Parser::consume_a_function(TokenStream&); - -template void Parser::consume_a_function_and_do_nothing(TokenStream&); -template void Parser::consume_a_function_and_do_nothing(TokenStream&); - template Optional Parser::consume_a_declaration(TokenStream&, Nested); template Optional Parser::consume_a_declaration(TokenStream&, Nested);