mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-09 09:39:39 +00:00
LibWeb+LibXML: Cache the result of parsing the XHTML DTD and reuse it
There's no reason to parse this again and again every time we parse an XHTML document.
This commit is contained in:
parent
6a5bca1302
commit
24c2ad059b
Notes:
github-actions[bot]
2024-10-12 23:02:08 +00:00
Author: https://github.com/alimpfard
Commit: 24c2ad059b
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1754
5 changed files with 38 additions and 19 deletions
|
@ -573,15 +573,21 @@ ErrorOr<void, ParseError> Parser::parse_doctype_decl()
|
|||
if (m_options.resolve_external_resource) {
|
||||
auto resource_result = m_options.resolve_external_resource(doctype.external_id->system_id, doctype.external_id->public_id);
|
||||
if (!resource_result.is_error()) {
|
||||
StringView resolved_source = resource_result.value();
|
||||
TemporaryChange source { m_source, resolved_source };
|
||||
TemporaryChange lexer { m_lexer, LineTrackingLexer(m_source) };
|
||||
auto declarations = TRY(parse_external_subset());
|
||||
if (!m_lexer.is_eof()) {
|
||||
return parse_error(
|
||||
m_lexer.current_position(),
|
||||
ByteString::formatted("Failed to resolve external subset '{}': garbage after declarations", doctype.external_id->system_id.system_literal));
|
||||
}
|
||||
auto declarations = TRY(resource_result.release_value().visit(
|
||||
[&](ByteString resolved_source) -> ErrorOr<Vector<MarkupDeclaration>, ParseError> {
|
||||
TemporaryChange source { m_source, resolved_source.view() };
|
||||
TemporaryChange lexer { m_lexer, LineTrackingLexer(m_source) };
|
||||
auto declarations = TRY(parse_external_subset());
|
||||
if (!m_lexer.is_eof()) {
|
||||
return parse_error(
|
||||
m_lexer.current_position(),
|
||||
ByteString::formatted("Failed to resolve external subset '{}': garbage after declarations", doctype.external_id->system_id.system_literal));
|
||||
}
|
||||
return declarations;
|
||||
},
|
||||
[&](Vector<MarkupDeclaration> declarations) -> ErrorOr<Vector<MarkupDeclaration>, ParseError> {
|
||||
return declarations;
|
||||
}));
|
||||
doctype.markup_declarations.extend(move(declarations));
|
||||
}
|
||||
}
|
||||
|
@ -1755,7 +1761,10 @@ ErrorOr<ByteString, ParseError> Parser::resolve_reference(EntityReference const&
|
|||
if (result.is_error())
|
||||
return parse_error(m_lexer.position_for(0), ByteString::formatted("Failed to resolve external entity '{}': {}", reference.name, result.error()));
|
||||
|
||||
resolved = result.release_value();
|
||||
if (!result.value().has<ByteString>())
|
||||
return parse_error(m_lexer.position_for(0), ByteString::formatted("Failed to resolve external entity '{}': Resource is of the wrong type", reference.name));
|
||||
|
||||
resolved = result.release_value().get<ByteString>();
|
||||
return {};
|
||||
}));
|
||||
break;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue