mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 20:28:11 +00:00
LibWeb: Remove StringBuilders from HTMLToken::AttributeBuilder
This commit is contained in:
parent
992964aa7d
commit
901d71148b
4 changed files with 41 additions and 33 deletions
|
@ -437,7 +437,7 @@ NonnullRefPtr<DOM::Element> HTMLDocumentParser::create_element_for(const HTMLTok
|
||||||
{
|
{
|
||||||
auto element = create_element(document(), token.tag_name(), namespace_);
|
auto element = create_element(document(), token.tag_name(), namespace_);
|
||||||
for (auto& attribute : token.m_tag.attributes) {
|
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;
|
return element;
|
||||||
}
|
}
|
||||||
|
@ -1120,9 +1120,9 @@ void HTMLDocumentParser::handle_in_body(HTMLToken& token)
|
||||||
if (m_stack_of_open_elements.contains(HTML::TagNames::template_))
|
if (m_stack_of_open_elements.contains(HTML::TagNames::template_))
|
||||||
return;
|
return;
|
||||||
for (auto& attribute : token.m_tag.attributes) {
|
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;
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1147,9 +1147,9 @@ void HTMLDocumentParser::handle_in_body(HTMLToken& token)
|
||||||
m_frameset_ok = false;
|
m_frameset_ok = false;
|
||||||
auto& body_element = m_stack_of_open_elements.elements().at(1);
|
auto& body_element = m_stack_of_open_elements.elements().at(1);
|
||||||
for (auto& attribute : token.m_tag.attributes) {
|
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;
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,9 +43,9 @@ String HTMLToken::to_string() const
|
||||||
builder.append(m_tag.tag_name.to_string());
|
builder.append(m_tag.tag_name.to_string());
|
||||||
builder.append("', { ");
|
builder.append("', { ");
|
||||||
for (auto& attribute : m_tag.attributes) {
|
for (auto& attribute : m_tag.attributes) {
|
||||||
builder.append(attribute.local_name_builder.to_string());
|
builder.append(attribute.local_name);
|
||||||
builder.append("=\"");
|
builder.append("=\"");
|
||||||
builder.append(attribute.value_builder.to_string());
|
builder.append(attribute.value);
|
||||||
builder.append("\" ");
|
builder.append("\" ");
|
||||||
}
|
}
|
||||||
builder.append("} }");
|
builder.append("} }");
|
||||||
|
|
|
@ -106,8 +106,8 @@ public:
|
||||||
{
|
{
|
||||||
VERIFY(is_start_tag() || is_end_tag());
|
VERIFY(is_start_tag() || is_end_tag());
|
||||||
for (auto& attribute : m_tag.attributes) {
|
for (auto& attribute : m_tag.attributes) {
|
||||||
if (attribute_name == attribute.local_name_builder.string_view())
|
if (attribute_name == attribute.local_name)
|
||||||
return attribute.value_builder.string_view();
|
return attribute.value;
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
@ -130,9 +130,8 @@ public:
|
||||||
{
|
{
|
||||||
VERIFY(is_start_tag() || is_end_tag());
|
VERIFY(is_start_tag() || is_end_tag());
|
||||||
for (auto& attribute : m_tag.attributes) {
|
for (auto& attribute : m_tag.attributes) {
|
||||||
if (old_name == attribute.local_name_builder.string_view()) {
|
if (old_name == attribute.local_name) {
|
||||||
attribute.local_name_builder.clear();
|
attribute.local_name = new_name;
|
||||||
attribute.local_name_builder.append(new_name);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -141,12 +140,9 @@ public:
|
||||||
{
|
{
|
||||||
VERIFY(is_start_tag() || is_end_tag());
|
VERIFY(is_start_tag() || is_end_tag());
|
||||||
for (auto& attribute : m_tag.attributes) {
|
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.prefix = prefix;
|
||||||
|
attribute.local_name = local_name;
|
||||||
attribute.local_name_builder.clear();
|
|
||||||
attribute.local_name_builder.append(local_name);
|
|
||||||
|
|
||||||
attribute.namespace_ = namespace_;
|
attribute.namespace_ = namespace_;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -179,9 +175,9 @@ private:
|
||||||
|
|
||||||
struct AttributeBuilder {
|
struct AttributeBuilder {
|
||||||
String prefix;
|
String prefix;
|
||||||
StringBuilder local_name_builder;
|
String local_name;
|
||||||
String namespace_;
|
String namespace_;
|
||||||
StringBuilder value_builder;
|
String value;
|
||||||
Position name_start_position;
|
Position name_start_position;
|
||||||
Position value_start_position;
|
Position value_start_position;
|
||||||
Position name_end_position;
|
Position name_end_position;
|
||||||
|
|
|
@ -78,7 +78,7 @@ namespace Web::HTML {
|
||||||
do { \
|
do { \
|
||||||
for (auto code_point : m_temporary_buffer) { \
|
for (auto code_point : m_temporary_buffer) { \
|
||||||
if (consumed_as_part_of_an_attribute()) { \
|
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 { \
|
} else { \
|
||||||
create_new_token(HTMLToken::Type::Character); \
|
create_new_token(HTMLToken::Type::Character); \
|
||||||
m_current_token.m_comment_or_character.data.append_code_point(code_point); \
|
m_current_token.m_comment_or_character.data.append_code_point(code_point); \
|
||||||
|
@ -1007,9 +1007,9 @@ _StartOfFunction:
|
||||||
log_parse_error();
|
log_parse_error();
|
||||||
auto new_attribute = HTMLToken::AttributeBuilder();
|
auto new_attribute = HTMLToken::AttributeBuilder();
|
||||||
new_attribute.name_start_position = nth_last_position(1);
|
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);
|
m_current_token.m_tag.attributes.append(new_attribute);
|
||||||
SWITCH_TO(AttributeName);
|
SWITCH_TO_WITH_UNCLEAN_BUILDER(AttributeName);
|
||||||
}
|
}
|
||||||
ANYTHING_ELSE
|
ANYTHING_ELSE
|
||||||
{
|
{
|
||||||
|
@ -1045,34 +1045,39 @@ _StartOfFunction:
|
||||||
{
|
{
|
||||||
ON_WHITESPACE
|
ON_WHITESPACE
|
||||||
{
|
{
|
||||||
|
m_current_token.m_tag.attributes.last().local_name = consume_current_builder();
|
||||||
RECONSUME_IN(AfterAttributeName);
|
RECONSUME_IN(AfterAttributeName);
|
||||||
}
|
}
|
||||||
ON('/')
|
ON('/')
|
||||||
{
|
{
|
||||||
|
m_current_token.m_tag.attributes.last().local_name = consume_current_builder();
|
||||||
RECONSUME_IN(AfterAttributeName);
|
RECONSUME_IN(AfterAttributeName);
|
||||||
}
|
}
|
||||||
ON('>')
|
ON('>')
|
||||||
{
|
{
|
||||||
|
m_current_token.m_tag.attributes.last().local_name = consume_current_builder();
|
||||||
RECONSUME_IN(AfterAttributeName);
|
RECONSUME_IN(AfterAttributeName);
|
||||||
}
|
}
|
||||||
ON_EOF
|
ON_EOF
|
||||||
{
|
{
|
||||||
|
m_current_token.m_tag.attributes.last().local_name = consume_current_builder();
|
||||||
RECONSUME_IN(AfterAttributeName);
|
RECONSUME_IN(AfterAttributeName);
|
||||||
}
|
}
|
||||||
ON('=')
|
ON('=')
|
||||||
{
|
{
|
||||||
m_current_token.m_tag.attributes.last().name_end_position = nth_last_position(1);
|
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);
|
SWITCH_TO(BeforeAttributeValue);
|
||||||
}
|
}
|
||||||
ON_ASCII_UPPER_ALPHA
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
ON(0)
|
ON(0)
|
||||||
{
|
{
|
||||||
log_parse_error();
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
ON('"')
|
ON('"')
|
||||||
|
@ -1093,7 +1098,7 @@ _StartOfFunction:
|
||||||
ANYTHING_ELSE
|
ANYTHING_ELSE
|
||||||
{
|
{
|
||||||
AnythingElseAttributeName:
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1163,17 +1168,19 @@ _StartOfFunction:
|
||||||
{
|
{
|
||||||
ON('"')
|
ON('"')
|
||||||
{
|
{
|
||||||
|
m_current_token.m_tag.attributes.last().value = consume_current_builder();
|
||||||
SWITCH_TO(AfterAttributeValueQuoted);
|
SWITCH_TO(AfterAttributeValueQuoted);
|
||||||
}
|
}
|
||||||
ON('&')
|
ON('&')
|
||||||
{
|
{
|
||||||
|
m_current_token.m_tag.attributes.last().value = consume_current_builder();
|
||||||
m_return_state = State::AttributeValueDoubleQuoted;
|
m_return_state = State::AttributeValueDoubleQuoted;
|
||||||
SWITCH_TO(CharacterReference);
|
SWITCH_TO(CharacterReference);
|
||||||
}
|
}
|
||||||
ON(0)
|
ON(0)
|
||||||
{
|
{
|
||||||
log_parse_error();
|
log_parse_error();
|
||||||
m_current_token.m_tag.attributes.last().value_builder.append_code_point(0xFFFD);
|
m_current_builder.append_code_point(0xFFFD);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ON_EOF
|
ON_EOF
|
||||||
|
@ -1183,7 +1190,7 @@ _StartOfFunction:
|
||||||
}
|
}
|
||||||
ANYTHING_ELSE
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1193,17 +1200,19 @@ _StartOfFunction:
|
||||||
{
|
{
|
||||||
ON('\'')
|
ON('\'')
|
||||||
{
|
{
|
||||||
|
m_current_token.m_tag.attributes.last().value = consume_current_builder();
|
||||||
SWITCH_TO(AfterAttributeValueQuoted);
|
SWITCH_TO(AfterAttributeValueQuoted);
|
||||||
}
|
}
|
||||||
ON('&')
|
ON('&')
|
||||||
{
|
{
|
||||||
|
m_current_token.m_tag.attributes.last().value = consume_current_builder();
|
||||||
m_return_state = State::AttributeValueSingleQuoted;
|
m_return_state = State::AttributeValueSingleQuoted;
|
||||||
SWITCH_TO(CharacterReference);
|
SWITCH_TO(CharacterReference);
|
||||||
}
|
}
|
||||||
ON(0)
|
ON(0)
|
||||||
{
|
{
|
||||||
log_parse_error();
|
log_parse_error();
|
||||||
m_current_token.m_tag.attributes.last().value_builder.append_code_point(0xFFFD);
|
m_current_builder.append_code_point(0xFFFD);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ON_EOF
|
ON_EOF
|
||||||
|
@ -1213,7 +1222,7 @@ _StartOfFunction:
|
||||||
}
|
}
|
||||||
ANYTHING_ELSE
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1223,23 +1232,26 @@ _StartOfFunction:
|
||||||
{
|
{
|
||||||
ON_WHITESPACE
|
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);
|
SWITCH_TO(BeforeAttributeName);
|
||||||
}
|
}
|
||||||
ON('&')
|
ON('&')
|
||||||
{
|
{
|
||||||
|
m_current_token.m_tag.attributes.last().value = consume_current_builder();
|
||||||
m_return_state = State::AttributeValueUnquoted;
|
m_return_state = State::AttributeValueUnquoted;
|
||||||
SWITCH_TO(CharacterReference);
|
SWITCH_TO(CharacterReference);
|
||||||
}
|
}
|
||||||
ON('>')
|
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);
|
m_current_token.m_tag.attributes.last().value_end_position = nth_last_position(1);
|
||||||
SWITCH_TO_AND_EMIT_CURRENT_TOKEN(Data);
|
SWITCH_TO_AND_EMIT_CURRENT_TOKEN(Data);
|
||||||
}
|
}
|
||||||
ON(0)
|
ON(0)
|
||||||
{
|
{
|
||||||
log_parse_error();
|
log_parse_error();
|
||||||
m_current_token.m_tag.attributes.last().value_builder.append_code_point(0xFFFD);
|
m_current_builder.append_code_point(0xFFFD);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ON('"')
|
ON('"')
|
||||||
|
@ -1275,7 +1287,7 @@ _StartOfFunction:
|
||||||
ANYTHING_ELSE
|
ANYTHING_ELSE
|
||||||
{
|
{
|
||||||
AnythingElseAttributeValueUnquoted:
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1584,7 +1596,7 @@ _StartOfFunction:
|
||||||
ON_ASCII_ALPHANUMERIC
|
ON_ASCII_ALPHANUMERIC
|
||||||
{
|
{
|
||||||
if (consumed_as_part_of_an_attribute()) {
|
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;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
EMIT_CURRENT_CHARACTER;
|
EMIT_CURRENT_CHARACTER;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue