mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-01-06 16:45:03 +00:00
LibWeb: Cache the Document's node navigable when possible
To avoid expensive lookups, we now cache a weak pointer from document to the last known node navigable. Before using the cache, we validate that the document is still the navigable's active document.
This commit is contained in:
committed by
Andreas Kling
parent
936b76f36e
commit
e746b2b133
@@ -362,9 +362,17 @@ void Node::set_node_value(Optional<String> const& maybe_value)
|
||||
// https://html.spec.whatwg.org/multipage/document-sequences.html#node-navigable
|
||||
JS::GCPtr<HTML::Navigable> Node::navigable() const
|
||||
{
|
||||
auto& document = const_cast<Document&>(this->document());
|
||||
if (auto cached_navigable = document.cached_navigable()) {
|
||||
if (cached_navigable->active_document() == &document)
|
||||
return cached_navigable;
|
||||
}
|
||||
|
||||
// To get the node navigable of a node node, return the navigable whose active document is node's node document,
|
||||
// or null if there is no such navigable.
|
||||
return HTML::Navigable::navigable_with_active_document(const_cast<Document&>(document()));
|
||||
auto navigable = HTML::Navigable::navigable_with_active_document(document);
|
||||
document.set_cached_navigable(navigable);
|
||||
return navigable;
|
||||
}
|
||||
|
||||
void Node::invalidate_style()
|
||||
|
||||
Reference in New Issue
Block a user