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/HTML/HTMLBaseElement.cpp | |
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/HTML/HTMLBaseElement.cpp')
-rw-r--r-- | Userland/Libraries/LibWeb/HTML/HTMLBaseElement.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLBaseElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLBaseElement.cpp index 19f28a84fc..675442986f 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLBaseElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLBaseElement.cpp @@ -21,6 +21,8 @@ void HTMLBaseElement::inserted() { HTMLElement::inserted(); + document().update_base_element({}); + // The frozen base URL must be immediately set for an element whenever any of the following situations occur: // - The base element becomes the first base element in tree order with an href content attribute in its Document. @@ -30,6 +32,12 @@ void HTMLBaseElement::inserted() set_the_frozen_base_url(); } +void HTMLBaseElement::removed_from(Node* parent) +{ + HTMLElement::removed_from(parent); + document().update_base_element({}); +} + void HTMLBaseElement::parse_attribute(FlyString const& name, String const& value) { HTMLElement::parse_attribute(name, value); @@ -39,6 +47,8 @@ void HTMLBaseElement::parse_attribute(FlyString const& name, String const& value if (name != AttributeNames::href) return; + document().update_base_element({}); + auto first_base_element_with_href_in_document = document().first_base_element_with_href_in_tree_order(); if (first_base_element_with_href_in_document.ptr() == this) set_the_frozen_base_url(); |