diff options
author | Andreas Kling <kling@serenityos.org> | 2022-11-04 20:56:30 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-11-05 00:30:10 +0100 |
commit | b400a349842b1565d9f04592e7d0fd180ff71456 (patch) | |
tree | 69875ad610ccd32554a102d780dbb6b0331c7861 /Userland/Libraries/LibWeb/DOM/Document.h | |
parent | 0aca69853c670ae6e4abe1aee420495ed8b65fd3 (diff) | |
download | serenity-b400a349842b1565d9f04592e7d0fd180ff71456.zip |
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.
Diffstat (limited to 'Userland/Libraries/LibWeb/DOM/Document.h')
-rw-r--r-- | Userland/Libraries/LibWeb/DOM/Document.h | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/DOM/Document.h b/Userland/Libraries/LibWeb/DOM/Document.h index 14e667559c..fcab4c06b9 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.h +++ b/Userland/Libraries/LibWeb/DOM/Document.h @@ -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; }; } |