diff options
author | Gunnar Beutner <gbeutner@serenityos.org> | 2021-05-23 09:16:07 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-07-14 23:03:36 +0200 |
commit | 3aa202c432d7dcf694eddf0a4d7b9ed5f46ce96a (patch) | |
tree | 1fae101cbcc8ae140e0e305954e6331072ddea36 /Userland/Libraries/LibWeb/HTML | |
parent | 901d71148b993e08459a0cd2d933d7e50706838e (diff) | |
download | serenity-3aa202c432d7dcf694eddf0a4d7b9ed5f46ce96a.zip |
LibWeb: Remove StringBuilder from HTMLToken::m_tag
Diffstat (limited to 'Userland/Libraries/LibWeb/HTML')
4 files changed, 33 insertions, 21 deletions
diff --git a/Userland/Libraries/LibWeb/HTML/Parser/HTMLDocumentParser.cpp b/Userland/Libraries/LibWeb/HTML/Parser/HTMLDocumentParser.cpp index 80aacf0905..fb3f82f5dd 100644 --- a/Userland/Libraries/LibWeb/HTML/Parser/HTMLDocumentParser.cpp +++ b/Userland/Libraries/LibWeb/HTML/Parser/HTMLDocumentParser.cpp @@ -1572,8 +1572,7 @@ void HTMLDocumentParser::handle_in_body(HTMLToken& token) if (token.is_start_tag() && token.tag_name() == HTML::TagNames::image) { // Parse error. Change the token's tag name to HTML::TagNames::img and reprocess it. (Don't ask.) log_parse_error(); - token.m_tag.tag_name.clear(); - token.m_tag.tag_name.append(HTML::TagNames::img); + token.m_tag.tag_name = "img"; process_using_the_rules_for(m_insertion_mode, token); return; } diff --git a/Userland/Libraries/LibWeb/HTML/Parser/HTMLToken.cpp b/Userland/Libraries/LibWeb/HTML/Parser/HTMLToken.cpp index 10f577bd2b..eccf3c1723 100644 --- a/Userland/Libraries/LibWeb/HTML/Parser/HTMLToken.cpp +++ b/Userland/Libraries/LibWeb/HTML/Parser/HTMLToken.cpp @@ -40,7 +40,7 @@ String HTMLToken::to_string() const if (type() == HTMLToken::Type::StartTag || type() == HTMLToken::Type::EndTag) { builder.append(" { name: '"); - builder.append(m_tag.tag_name.to_string()); + builder.append(m_tag.tag_name); builder.append("', { "); for (auto& attribute : m_tag.attributes) { builder.append(attribute.local_name); diff --git a/Userland/Libraries/LibWeb/HTML/Parser/HTMLToken.h b/Userland/Libraries/LibWeb/HTML/Parser/HTMLToken.h index e3fb7fb29f..95475d8c1f 100644 --- a/Userland/Libraries/LibWeb/HTML/Parser/HTMLToken.h +++ b/Userland/Libraries/LibWeb/HTML/Parser/HTMLToken.h @@ -42,7 +42,7 @@ public: { HTMLToken token; token.m_type = Type::StartTag; - token.m_tag.tag_name.append(tag_name); + token.m_tag.tag_name = tag_name; return token; } @@ -81,7 +81,7 @@ public: String tag_name() const { VERIFY(is_start_tag() || is_end_tag()); - return m_tag.tag_name.to_string(); + return m_tag.tag_name; } bool is_self_closing() const @@ -120,10 +120,8 @@ public: void adjust_tag_name(const FlyString& old_name, const FlyString& new_name) { VERIFY(is_start_tag() || is_end_tag()); - if (old_name == m_tag.tag_name.string_view()) { - m_tag.tag_name.clear(); - m_tag.tag_name.append(new_name); - } + if (old_name == m_tag.tag_name) + m_tag.tag_name = new_name; } void adjust_attribute_name(const FlyString& old_name, const FlyString& new_name) @@ -202,7 +200,7 @@ private: // Type::StartTag // Type::EndTag struct { - StringBuilder tag_name; + String tag_name; bool self_closing { false }; bool self_closing_acknowledged { false }; Vector<AttributeBuilder> attributes; diff --git a/Userland/Libraries/LibWeb/HTML/Parser/HTMLTokenizer.cpp b/Userland/Libraries/LibWeb/HTML/Parser/HTMLTokenizer.cpp index 44c3a7ba9b..312875ece5 100644 --- a/Userland/Libraries/LibWeb/HTML/Parser/HTMLTokenizer.cpp +++ b/Userland/Libraries/LibWeb/HTML/Parser/HTMLTokenizer.cpp @@ -303,29 +303,32 @@ _StartOfFunction: { ON_WHITESPACE { + m_current_token.m_tag.tag_name = consume_current_builder(); m_current_token.m_end_position = nth_last_position(1); SWITCH_TO(BeforeAttributeName); } ON('/') { + m_current_token.m_tag.tag_name = consume_current_builder(); m_current_token.m_end_position = nth_last_position(0); SWITCH_TO(SelfClosingStartTag); } ON('>') { + m_current_token.m_tag.tag_name = consume_current_builder(); m_current_token.m_end_position = nth_last_position(1); SWITCH_TO_AND_EMIT_CURRENT_TOKEN(Data); } ON_ASCII_UPPER_ALPHA { - m_current_token.m_tag.tag_name.append(to_ascii_lowercase(current_input_character.value())); + m_current_builder.append_code_point(to_ascii_lowercase(current_input_character.value())); m_current_token.m_end_position = nth_last_position(0); continue; } ON(0) { log_parse_error(); - m_current_token.m_tag.tag_name.append_code_point(0xFFFD); + m_current_builder.append_code_point(0xFFFD); m_current_token.m_end_position = nth_last_position(0); continue; } @@ -337,7 +340,7 @@ _StartOfFunction: } ANYTHING_ELSE { - m_current_token.m_tag.tag_name.append_code_point(current_input_character.value()); + m_current_builder.append_code_point(current_input_character.value()); m_current_token.m_end_position = nth_last_position(0); continue; } @@ -1846,6 +1849,7 @@ _StartOfFunction: { ON_WHITESPACE { + m_current_token.m_tag.tag_name = consume_current_builder(); if (!current_end_tag_token_is_appropriate()) { m_queued_tokens.enqueue(HTMLToken::make_character('<')); m_queued_tokens.enqueue(HTMLToken::make_character('/')); @@ -1857,6 +1861,7 @@ _StartOfFunction: } ON('/') { + m_current_token.m_tag.tag_name = consume_current_builder(); if (!current_end_tag_token_is_appropriate()) { m_queued_tokens.enqueue(HTMLToken::make_character('<')); m_queued_tokens.enqueue(HTMLToken::make_character('/')); @@ -1868,6 +1873,7 @@ _StartOfFunction: } ON('>') { + m_current_token.m_tag.tag_name = consume_current_builder(); if (!current_end_tag_token_is_appropriate()) { m_queued_tokens.enqueue(HTMLToken::make_character('<')); m_queued_tokens.enqueue(HTMLToken::make_character('/')); @@ -1879,13 +1885,13 @@ _StartOfFunction: } ON_ASCII_UPPER_ALPHA { - m_current_token.m_tag.tag_name.append(to_ascii_lowercase(current_input_character.value())); + m_current_builder.append_code_point(to_ascii_lowercase(current_input_character.value())); m_temporary_buffer.append(current_input_character.value()); continue; } ON_ASCII_LOWER_ALPHA { - m_current_token.m_tag.tag_name.append_code_point(current_input_character.value()); + m_current_builder.append_code_point(current_input_character.value()); m_temporary_buffer.append(current_input_character.value()); continue; } @@ -1956,6 +1962,7 @@ _StartOfFunction: { ON_WHITESPACE { + m_current_token.m_tag.tag_name = consume_current_builder(); if (!current_end_tag_token_is_appropriate()) { m_queued_tokens.enqueue(HTMLToken::make_character('<')); m_queued_tokens.enqueue(HTMLToken::make_character('/')); @@ -1967,6 +1974,7 @@ _StartOfFunction: } ON('/') { + m_current_token.m_tag.tag_name = consume_current_builder(); if (!current_end_tag_token_is_appropriate()) { m_queued_tokens.enqueue(HTMLToken::make_character('<')); m_queued_tokens.enqueue(HTMLToken::make_character('/')); @@ -1978,6 +1986,7 @@ _StartOfFunction: } ON('>') { + m_current_token.m_tag.tag_name = consume_current_builder(); if (!current_end_tag_token_is_appropriate()) { m_queued_tokens.enqueue(HTMLToken::make_character('<')); m_queued_tokens.enqueue(HTMLToken::make_character('/')); @@ -1989,13 +1998,13 @@ _StartOfFunction: } ON_ASCII_UPPER_ALPHA { - m_current_token.m_tag.tag_name.append(to_ascii_lowercase(current_input_character.value())); + m_current_builder.append_code_point(to_ascii_lowercase(current_input_character.value())); m_temporary_buffer.append(current_input_character.value()); continue; } ON_ASCII_LOWER_ALPHA { - m_current_token.m_tag.tag_name.append(current_input_character.value()); + m_current_builder.append(current_input_character.value()); m_temporary_buffer.append(current_input_character.value()); continue; } @@ -2166,6 +2175,7 @@ _StartOfFunction: { ON_WHITESPACE { + m_current_token.m_tag.tag_name = consume_current_builder(); if (current_end_tag_token_is_appropriate()) SWITCH_TO(BeforeAttributeName); @@ -2178,6 +2188,7 @@ _StartOfFunction: } ON('/') { + m_current_token.m_tag.tag_name = consume_current_builder(); if (current_end_tag_token_is_appropriate()) SWITCH_TO(SelfClosingStartTag); @@ -2190,6 +2201,7 @@ _StartOfFunction: } ON('>') { + m_current_token.m_tag.tag_name = consume_current_builder(); if (current_end_tag_token_is_appropriate()) SWITCH_TO_AND_EMIT_CURRENT_TOKEN(Data); @@ -2202,13 +2214,13 @@ _StartOfFunction: } ON_ASCII_UPPER_ALPHA { - m_current_token.m_tag.tag_name.append(to_ascii_lowercase(current_input_character.value())); + m_current_builder.append_code_point(to_ascii_lowercase(current_input_character.value())); m_temporary_buffer.append(current_input_character.value()); continue; } ON_ASCII_LOWER_ALPHA { - m_current_token.m_tag.tag_name.append(current_input_character.value()); + m_current_builder.append(current_input_character.value()); m_temporary_buffer.append(current_input_character.value()); continue; } @@ -2491,6 +2503,7 @@ _StartOfFunction: { ON_WHITESPACE { + m_current_token.m_tag.tag_name = consume_current_builder(); if (current_end_tag_token_is_appropriate()) SWITCH_TO(BeforeAttributeName); m_queued_tokens.enqueue(HTMLToken::make_character('<')); @@ -2501,6 +2514,7 @@ _StartOfFunction: } ON('/') { + m_current_token.m_tag.tag_name = consume_current_builder(); if (current_end_tag_token_is_appropriate()) SWITCH_TO(SelfClosingStartTag); m_queued_tokens.enqueue(HTMLToken::make_character('<')); @@ -2511,6 +2525,7 @@ _StartOfFunction: } ON('>') { + m_current_token.m_tag.tag_name = consume_current_builder(); if (current_end_tag_token_is_appropriate()) SWITCH_TO_AND_EMIT_CURRENT_TOKEN(Data); m_queued_tokens.enqueue(HTMLToken::make_character('<')); @@ -2521,13 +2536,13 @@ _StartOfFunction: } ON_ASCII_UPPER_ALPHA { - m_current_token.m_tag.tag_name.append(to_ascii_lowercase(current_input_character.value())); + m_current_builder.append_code_point(to_ascii_lowercase(current_input_character.value())); m_temporary_buffer.append(current_input_character.value()); continue; } ON_ASCII_LOWER_ALPHA { - m_current_token.m_tag.tag_name.append(current_input_character.value()); + m_current_builder.append(current_input_character.value()); m_temporary_buffer.append(current_input_character.value()); continue; } |