mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 14:17:36 +00:00
LibWeb: Cache the first <base href> (in tree order) in Document
When parsing relative URLs, we have to check the first <base href> in tree order (if one is available). This was getting *very* costly on large DOMs with many relative urls. This patch avoids all that repeated traversal by letting Document cache the first <base href> and invalidating the cache whenever a <base> element is added/removed/edited in the DOM. The browser was stuck doing this for a *very* long time when loading the ECMA-262 spec, and this removes that problem entirely.
This commit is contained in:
parent
0aca69853c
commit
b400a34984
4 changed files with 23 additions and 3 deletions
|
@ -342,7 +342,7 @@ void Document::visit_edges(Cell::Visitor& visitor)
|
|||
visitor.visit(m_scripts);
|
||||
visitor.visit(m_all);
|
||||
visitor.visit(m_selection);
|
||||
|
||||
visitor.visit(m_first_base_element_with_href_in_tree_order);
|
||||
visitor.visit(m_parser);
|
||||
|
||||
for (auto& script : m_scripts_to_execute_when_parsing_has_finished)
|
||||
|
@ -732,7 +732,7 @@ Vector<CSS::BackgroundLayerData> const* Document::background_layers() const
|
|||
return &body_layout_node->background_layers();
|
||||
}
|
||||
|
||||
JS::GCPtr<HTML::HTMLBaseElement> Document::first_base_element_with_href_in_tree_order() const
|
||||
void Document::update_base_element(Badge<HTML::HTMLBaseElement>)
|
||||
{
|
||||
JS::GCPtr<HTML::HTMLBaseElement> base_element;
|
||||
|
||||
|
@ -745,7 +745,12 @@ JS::GCPtr<HTML::HTMLBaseElement> Document::first_base_element_with_href_in_tree_
|
|||
return IterationDecision::Continue;
|
||||
});
|
||||
|
||||
return base_element;
|
||||
m_first_base_element_with_href_in_tree_order = base_element;
|
||||
}
|
||||
|
||||
JS::GCPtr<HTML::HTMLBaseElement> Document::first_base_element_with_href_in_tree_order() const
|
||||
{
|
||||
return m_first_base_element_with_href_in_tree_order;
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/urls-and-fetching.html#fallback-base-url
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue