1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 03:07: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:
Andreas Kling 2022-11-04 20:56:30 +01:00
parent 0aca69853c
commit b400a34984
4 changed files with 23 additions and 3 deletions

View file

@ -107,6 +107,7 @@ public:
AK::URL fallback_base_url() const;
AK::URL base_url() const;
void update_base_element(Badge<HTML::HTMLBaseElement>);
JS::GCPtr<HTML::HTMLBaseElement> first_base_element_with_href_in_tree_order() const;
String url_string() const { return m_url.to_string(); }
@ -601,6 +602,9 @@ private:
// https://w3c.github.io/selection-api/#dfn-selection
JS::GCPtr<Selection::Selection> m_selection;
// NOTE: This is a cache to make finding the first <base href> element O(1).
JS::GCPtr<HTML::HTMLBaseElement> m_first_base_element_with_href_in_tree_order;
};
}