mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 14:38:11 +00:00
LibWeb: Make HTMLCollection faster when it only cares about children
Some of the live HTMLCollection only ever contain children of their root node. When we know that's the case, we can avoid doing a full subtree traversal of all descendants and only visit children. This cuts the ECMA262 spec loading time by over 10 seconds. :^)
This commit is contained in:
parent
e31f696ee6
commit
df1bb0ff49
10 changed files with 54 additions and 41 deletions
|
@ -244,7 +244,7 @@ static bool is_form_control(DOM::Element const& element)
|
|||
JS::NonnullGCPtr<DOM::HTMLCollection> HTMLFormElement::elements() const
|
||||
{
|
||||
if (!m_elements) {
|
||||
m_elements = DOM::HTMLCollection::create(const_cast<HTMLFormElement&>(*this), [](Element const& element) {
|
||||
m_elements = DOM::HTMLCollection::create(const_cast<HTMLFormElement&>(*this), DOM::HTMLCollection::Scope::Descendants, [](Element const& element) {
|
||||
return is_form_control(element);
|
||||
}).release_value_but_fixme_should_propagate_errors();
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<HTMLOptionsCollection>> HTMLOptionsCollecti
|
|||
}
|
||||
|
||||
HTMLOptionsCollection::HTMLOptionsCollection(DOM::ParentNode& root, Function<bool(DOM::Element const&)> filter)
|
||||
: DOM::HTMLCollection(root, move(filter))
|
||||
: DOM::HTMLCollection(root, Scope::Descendants, move(filter))
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -264,7 +264,7 @@ JS::NonnullGCPtr<DOM::HTMLCollection> HTMLTableElement::t_bodies()
|
|||
// The tBodies attribute must return an HTMLCollection rooted at the table node,
|
||||
// whose filter matches only tbody elements that are children of the table element.
|
||||
if (!m_t_bodies) {
|
||||
m_t_bodies = DOM::HTMLCollection::create(*this, [](DOM::Element const& element) {
|
||||
m_t_bodies = DOM::HTMLCollection::create(*this, DOM::HTMLCollection::Scope::Children, [](DOM::Element const& element) {
|
||||
return element.local_name() == TagNames::tbody;
|
||||
}).release_value_but_fixme_should_propagate_errors();
|
||||
}
|
||||
|
@ -307,7 +307,7 @@ JS::NonnullGCPtr<DOM::HTMLCollection> HTMLTableElement::rows()
|
|||
// How do you sort HTMLCollection?
|
||||
|
||||
if (!m_rows) {
|
||||
m_rows = DOM::HTMLCollection::create(*this, [table_node](DOM::Element const& element) {
|
||||
m_rows = DOM::HTMLCollection::create(*this, DOM::HTMLCollection::Scope::Descendants, [table_node](DOM::Element const& element) {
|
||||
// Only match TR elements which are:
|
||||
// * children of the table element
|
||||
// * children of the thead, tbody, or tfoot elements that are themselves children of the table element
|
||||
|
|
|
@ -42,9 +42,8 @@ JS::NonnullGCPtr<DOM::HTMLCollection> HTMLTableRowElement::cells() const
|
|||
// The cells attribute must return an HTMLCollection rooted at this tr element,
|
||||
// whose filter matches only td and th elements that are children of the tr element.
|
||||
if (!m_cells) {
|
||||
m_cells = DOM::HTMLCollection::create(const_cast<HTMLTableRowElement&>(*this), [this](Element const& element) {
|
||||
return element.parent() == this
|
||||
&& is<HTMLTableCellElement>(element);
|
||||
m_cells = DOM::HTMLCollection::create(const_cast<HTMLTableRowElement&>(*this), DOM::HTMLCollection::Scope::Children, [](Element const& element) {
|
||||
return is<HTMLTableCellElement>(element);
|
||||
}).release_value_but_fixme_should_propagate_errors();
|
||||
}
|
||||
return *m_cells;
|
||||
|
|
|
@ -41,9 +41,8 @@ JS::NonnullGCPtr<DOM::HTMLCollection> HTMLTableSectionElement::rows() const
|
|||
// The rows attribute must return an HTMLCollection rooted at this element,
|
||||
// whose filter matches only tr elements that are children of this element.
|
||||
if (!m_rows) {
|
||||
m_rows = DOM::HTMLCollection::create(const_cast<HTMLTableSectionElement&>(*this), [this](Element const& element) {
|
||||
return element.parent() == this
|
||||
&& is<HTMLTableRowElement>(element);
|
||||
m_rows = DOM::HTMLCollection::create(const_cast<HTMLTableSectionElement&>(*this), DOM::HTMLCollection::Scope::Children, [](Element const& element) {
|
||||
return is<HTMLTableRowElement>(element);
|
||||
}).release_value_but_fixme_should_propagate_errors();
|
||||
}
|
||||
return *m_rows;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue