diff options
author | Gunnar Beutner <gbeutner@serenityos.org> | 2021-05-23 08:50:48 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-07-14 23:03:36 +0200 |
commit | 901d71148b993e08459a0cd2d933d7e50706838e (patch) | |
tree | ab82924e4d220a2bdaf9ebed592f10448fffdf2c /Userland/Libraries/LibWeb/HTML | |
parent | 992964aa7d082aeecd7b3c1136ce602ff7ced923 (diff) | |
download | serenity-901d71148b993e08459a0cd2d933d7e50706838e.zip |
LibWeb: Remove StringBuilders from HTMLToken::AttributeBuilder
Diffstat (limited to 'Userland/Libraries/LibWeb/HTML')
4 files changed, 41 insertions, 33 deletions
diff --git a/Userland/Libraries/LibWeb/HTML/Parser/HTMLDocumentParser.cpp b/Userland/Libraries/LibWeb/HTML/Parser/HTMLDocumentParser.cpp index 06c7823523..80aacf0905 100644 --- a/Userland/Libraries/LibWeb/HTML/Parser/HTMLDocumentParser.cpp +++ b/Userland/Libraries/LibWeb/HTML/Parser/HTMLDocumentParser.cpp @@ -437,7 +437,7 @@ NonnullRefPtr<DOM::Element> HTMLDocumentParser::create_element_for(const HTMLTok { auto element = create_element(document(), token.tag_name(), namespace_); for (auto& attribute : token.m_tag.attributes) { - element->set_attribute(attribute.local_name_builder.to_string(), attribute.value_builder.to_string()); + element->set_attribute(attribute.local_name, attribute.value); } return element; } @@ -1120,9 +1120,9 @@ void HTMLDocumentParser::handle_in_body(HTMLToken& token) if (m_stack_of_open_elements.contains(HTML::TagNames::template_)) return; for (auto& attribute : token.m_tag.attributes) { - if (current_node().has_attribute(attribute.local_name_builder.string_view())) + if (current_node().has_attribute(attribute.local_name)) continue; - current_node().set_attribute(attribute.local_name_builder.to_string(), attribute.value_builder.to_string()); + current_node().set_attribute(attribute.local_name, attribute.value); } return; } @@ -1147,9 +1147,9 @@ void HTMLDocumentParser::handle_in_body(HTMLToken& token) m_frameset_ok = false; auto& body_element = m_stack_of_open_elements.elements().at(1); for (auto& attribute : token.m_tag.attributes) { - if (body_element.has_attribute(attribute.local_name_builder.string_view())) + if (body_element.has_attribute(attribute.local_name)) continue; - body_element.set_attribute(attribute.local_name_builder.to_string(), attribute.value_builder.to_string()); + body_element.set_attribute(attribute.local_name, attribute.value); } return; } diff --git a/Userland/Libraries/LibWeb/HTML/Parser/HTMLToken.cpp b/Userland/Libraries/LibWeb/HTML/Parser/HTMLToken.cpp index 09348360fd..10f577bd2b 100644 --- a/Userland/Libraries/LibWeb/HTML/Parser/HTMLToken.cpp +++ b/Userland/Libraries/LibWeb/HTML/Parser/HTMLToken.cpp @@ -43,9 +43,9 @@ String HTMLToken::to_string() const builder.append(m_tag.tag_name.to_string()); builder.append("', { "); for (auto& attribute : m_tag.attributes) { - builder.append(attribute.local_name_builder.to_string()); + builder.append(attribute.local_name); builder.append("=\""); - builder.append(attribute.value_builder.to_string()); + builder.append(attribute.value); builder.append("\" "); } builder.append("} }"); diff --git a/Userland/Libraries/LibWeb/HTML/Parser/HTMLToken.h b/Userland/Libraries/LibWeb/HTML/Parser/HTMLToken.h index 9f5a64d663..e3fb7fb29f 100644 --- a/Userland/Libraries/LibWeb/HTML/Parser/HTMLToken.h +++ b/Userland/Libraries/LibWeb/HTML/Parser/HTMLToken.h @@ -106,8 +106,8 @@ public: { VERIFY(is_start_tag() || is_end_tag()); for (auto& attribute : m_tag.attributes) { - if (attribute_name == attribute.local_name_builder.string_view()) - return attribute.value_builder.string_view(); + if (attribute_name == attribute.local_name) + return attribute.value; } return {}; } @@ -130,9 +130,8 @@ public: { VERIFY(is_start_tag() || is_end_tag()); for (auto& attribute : m_tag.attributes) { - if (old_name == attribute.local_name_builder.string_view()) { - attribute.local_name_builder.clear(); - attribute.local_name_builder.append(new_name); + if (old_name == attribute.local_name) { + attribute.local_name = new_name; } } } @@ -141,12 +140,9 @@ public: { VERIFY(is_start_tag() || is_end_tag()); for (auto& attribute : m_tag.attributes) { - if (old_name == attribute.local_name_builder.string_view()) { + if (old_name == attribute.local_name) { attribute.prefix = prefix; - - attribute.local_name_builder.clear(); - attribute.local_name_builder.append(local_name); - + attribute.local_name = local_name; attribute.namespace_ = namespace_; } } @@ -179,9 +175,9 @@ private: struct AttributeBuilder { String prefix; - StringBuilder local_name_builder; + String local_name; String namespace_; - StringBuilder value_builder; + String value; Position name_start_position; Position value_start_position; Position name_end_position; diff --git a/Userland/Libraries/LibWeb/HTML/Parser/HTMLTokenizer.cpp b/Userland/Libraries/LibWeb/HTML/Parser/HTMLTokenizer.cpp index 541f66c7f7..44c3a7ba9b 100644 --- a/Userland/Libraries/LibWeb/HTML/Parser/HTMLTokenizer.cpp +++ b/Userland/Libraries/LibWeb/HTML/Parser/HTMLTokenizer.cpp @@ -78,7 +78,7 @@ namespace Web::HTML { do { \ for (auto code_point : m_temporary_buffer) { \ if (consumed_as_part_of_an_attribute()) { \ - m_current_token.m_tag.attributes.last().value_builder.append_code_point(code_point); \ + m_current_builder.append_code_point(code_point); \ } else { \ create_new_token(HTMLToken::Type::Character); \ m_current_token.m_comment_or_character.data.append_code_point(code_point); \ @@ -1007,9 +1007,9 @@ _StartOfFunction: log_parse_error(); auto new_attribute = HTMLToken::AttributeBuilder(); new_attribute.name_start_position = nth_last_position(1); - new_attribute.local_name_builder.append_code_point(current_input_character.value()); + m_current_builder.append_code_point(current_input_character.value()); m_current_token.m_tag.attributes.append(new_attribute); - SWITCH_TO(AttributeName); + SWITCH_TO_WITH_UNCLEAN_BUILDER(AttributeName); } ANYTHING_ELSE { @@ -1045,34 +1045,39 @@ _StartOfFunction: { ON_WHITESPACE { + m_current_token.m_tag.attributes.last().local_name = consume_current_builder(); RECONSUME_IN(AfterAttributeName); } ON('/') { + m_current_token.m_tag.attributes.last().local_name = consume_current_builder(); RECONSUME_IN(AfterAttributeName); } ON('>') { + m_current_token.m_tag.attributes.last().local_name = consume_current_builder(); RECONSUME_IN(AfterAttributeName); } ON_EOF { + m_current_token.m_tag.attributes.last().local_name = consume_current_builder(); RECONSUME_IN(AfterAttributeName); } ON('=') { m_current_token.m_tag.attributes.last().name_end_position = nth_last_position(1); + m_current_token.m_tag.attributes.last().local_name = consume_current_builder(); SWITCH_TO(BeforeAttributeValue); } ON_ASCII_UPPER_ALPHA { - m_current_token.m_tag.attributes.last().local_name_builder.append_code_point(to_ascii_lowercase(current_input_character.value())); + m_current_builder.append_code_point(to_ascii_lowercase(current_input_character.value())); continue; } ON(0) { log_parse_error(); - m_current_token.m_tag.attributes.last().local_name_builder.append_code_point(0xFFFD); + m_current_builder.append_code_point(0xFFFD); continue; } ON('"') @@ -1093,7 +1098,7 @@ _StartOfFunction: ANYTHING_ELSE { AnythingElseAttributeName: - m_current_token.m_tag.attributes.last().local_name_builder.append_code_point(current_input_character.value()); + m_current_builder.append_code_point(current_input_character.value()); continue; } } @@ -1163,17 +1168,19 @@ _StartOfFunction: { ON('"') { + m_current_token.m_tag.attributes.last().value = consume_current_builder(); SWITCH_TO(AfterAttributeValueQuoted); } ON('&') { + m_current_token.m_tag.attributes.last().value = consume_current_builder(); m_return_state = State::AttributeValueDoubleQuoted; SWITCH_TO(CharacterReference); } ON(0) { log_parse_error(); - m_current_token.m_tag.attributes.last().value_builder.append_code_point(0xFFFD); + m_current_builder.append_code_point(0xFFFD); continue; } ON_EOF @@ -1183,7 +1190,7 @@ _StartOfFunction: } ANYTHING_ELSE { - m_current_token.m_tag.attributes.last().value_builder.append_code_point(current_input_character.value()); + m_current_builder.append_code_point(current_input_character.value()); continue; } } @@ -1193,17 +1200,19 @@ _StartOfFunction: { ON('\'') { + m_current_token.m_tag.attributes.last().value = consume_current_builder(); SWITCH_TO(AfterAttributeValueQuoted); } ON('&') { + m_current_token.m_tag.attributes.last().value = consume_current_builder(); m_return_state = State::AttributeValueSingleQuoted; SWITCH_TO(CharacterReference); } ON(0) { log_parse_error(); - m_current_token.m_tag.attributes.last().value_builder.append_code_point(0xFFFD); + m_current_builder.append_code_point(0xFFFD); continue; } ON_EOF @@ -1213,7 +1222,7 @@ _StartOfFunction: } ANYTHING_ELSE { - m_current_token.m_tag.attributes.last().value_builder.append_code_point(current_input_character.value()); + m_current_builder.append_code_point(current_input_character.value()); continue; } } @@ -1223,23 +1232,26 @@ _StartOfFunction: { ON_WHITESPACE { - m_current_token.m_tag.attributes.last().value_end_position = nth_last_position(1); + m_current_token.m_tag.attributes.last().value = consume_current_builder(); + m_current_token.m_tag.attributes.last().value_end_position = nth_last_position(2); SWITCH_TO(BeforeAttributeName); } ON('&') { + m_current_token.m_tag.attributes.last().value = consume_current_builder(); m_return_state = State::AttributeValueUnquoted; SWITCH_TO(CharacterReference); } ON('>') { + m_current_token.m_tag.attributes.last().value = consume_current_builder(); m_current_token.m_tag.attributes.last().value_end_position = nth_last_position(1); SWITCH_TO_AND_EMIT_CURRENT_TOKEN(Data); } ON(0) { log_parse_error(); - m_current_token.m_tag.attributes.last().value_builder.append_code_point(0xFFFD); + m_current_builder.append_code_point(0xFFFD); continue; } ON('"') @@ -1275,7 +1287,7 @@ _StartOfFunction: ANYTHING_ELSE { AnythingElseAttributeValueUnquoted: - m_current_token.m_tag.attributes.last().value_builder.append_code_point(current_input_character.value()); + m_current_builder.append_code_point(current_input_character.value()); continue; } } @@ -1584,7 +1596,7 @@ _StartOfFunction: ON_ASCII_ALPHANUMERIC { if (consumed_as_part_of_an_attribute()) { - m_current_token.m_tag.attributes.last().value_builder.append_code_point(current_input_character.value()); + m_current_builder.append_code_point(current_input_character.value()); continue; } else { EMIT_CURRENT_CHARACTER; |