LibWeb: Stop creating transient throwaway JS::Handles in HTML parser

These were being immediately stored in JS::GCPtrs (and dutifully visited
by HTMLParser), so creating temporary handles for them was a complete
waste of time.
This commit is contained in:
Andreas Kling 2024-07-20 14:38:32 +02:00 committed by Andreas Kling
parent dba6216caa
commit f9f11dc51d
Notes: github-actions[bot] 2024-07-20 13:36:27 +00:00

View file

@ -138,7 +138,7 @@ static bool is_html_integration_point(DOM::Element const& element)
HTMLParser::HTMLParser(DOM::Document& document, StringView input, StringView encoding)
: m_tokenizer(input, encoding)
, m_scripting_enabled(document.is_scripting_enabled())
, m_document(JS::make_handle(document))
, m_document(document)
{
m_tokenizer.set_parser({}, *this);
m_document->set_parser({}, *this);
@ -149,7 +149,7 @@ HTMLParser::HTMLParser(DOM::Document& document, StringView input, StringView enc
HTMLParser::HTMLParser(DOM::Document& document)
: m_scripting_enabled(document.is_scripting_enabled())
, m_document(JS::make_handle(document))
, m_document(document)
{
m_document->set_parser({}, *this);
m_tokenizer.set_parser({}, *this);
@ -810,7 +810,7 @@ void HTMLParser::handle_before_head(HTMLToken& token)
if (token.is_start_tag() && token.tag_name() == HTML::TagNames::head) {
auto element = insert_html_element(token);
m_head_element = JS::make_handle(verify_cast<HTMLHeadElement>(*element));
m_head_element = verify_cast<HTMLHeadElement>(*element);
m_insertion_mode = InsertionMode::InHead;
return;
}
@ -825,7 +825,7 @@ void HTMLParser::handle_before_head(HTMLToken& token)
}
AnythingElse:
m_head_element = JS::make_handle(verify_cast<HTMLHeadElement>(*insert_html_element(HTMLToken::make_start_tag(HTML::TagNames::head))));
m_head_element = verify_cast<HTMLHeadElement>(*insert_html_element(HTMLToken::make_start_tag(HTML::TagNames::head)));
m_insertion_mode = InsertionMode::InHead;
process_using_the_rules_for(InsertionMode::InHead, token);
return;
@ -1159,12 +1159,12 @@ void HTMLParser::insert_character(u32 data)
return;
}
if (!m_character_insertion_node.ptr()) {
m_character_insertion_node = JS::make_handle(node);
m_character_insertion_node = node;
m_character_insertion_builder.append_code_point(data);
return;
}
flush_character_insertions();
m_character_insertion_node = JS::make_handle(node);
m_character_insertion_node = node;
m_character_insertion_builder.append_code_point(data);
}
@ -1366,7 +1366,7 @@ Create:
auto new_element = insert_html_element(HTMLToken::make_start_tag(entry->element->local_name()));
// 9. Replace the entry for entry in the list with an entry for new element.
m_list_of_active_formatting_elements.entries().at(index).element = JS::make_handle(new_element);
m_list_of_active_formatting_elements.entries().at(index).element = new_element;
// 10. If the entry for new element in the list of active formatting elements is not the last entry in the list, return to the step labeled advance.
if (index != m_list_of_active_formatting_elements.entries().size() - 1)
@ -1934,7 +1934,7 @@ void HTMLParser::handle_in_body(HTMLToken& token)
// Insert an HTML element for the token, and, if there is no template element on the stack of open elements, set the form element pointer to point to the element created.
auto element = insert_html_element(token);
if (!m_stack_of_open_elements.contains(HTML::TagNames::template_))
m_form_element = JS::make_handle(verify_cast<HTMLFormElement>(*element));
m_form_element = verify_cast<HTMLFormElement>(*element);
return;
}
@ -3461,7 +3461,7 @@ void HTMLParser::handle_in_table(HTMLToken& token)
// Otherwise:
// Insert an HTML element for the token, and set the form element pointer to point to the element created.
m_form_element = JS::make_handle(verify_cast<HTMLFormElement>(*insert_html_element(token)));
m_form_element = verify_cast<HTMLFormElement>(*insert_html_element(token));
// Pop that form element off the stack of open elements.
(void)m_stack_of_open_elements.pop();
@ -4285,7 +4285,7 @@ Vector<JS::Handle<DOM::Node>> HTMLParser::parse_html_fragment(DOM::Element& cont
// 4. Create a new HTML parser, and associate it with the just created Document node.
auto parser = HTMLParser::create(*temp_document, markup, "utf-8"sv);
parser->m_context_element = JS::make_handle(context_element);
parser->m_context_element = context_element;
parser->m_parsing_fragment = true;
// 5. Set the state of the HTML parser's tokenization stage as follows, switching on the context element: