mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-08 09:09:43 +00:00
LibWeb/HTML: Add fastpath to skip selectedness update on option insert
This extends the optimization introduced in the previous commit to also apply to the inserted steps for an option element. This makes the test: https://wpt.live/html/select/options-length-too-large.html Go from not ever completing due to how slow it was to running, to finishing in 800ms on my PC :^)
This commit is contained in:
parent
075c7ea63e
commit
ebd6d49415
Notes:
github-actions[bot]
2025-01-30 20:56:39 +00:00
Author: https://github.com/shannonbooth
Commit: ebd6d49415
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3373
Reviewed-by: https://github.com/ADKaster ✅
3 changed files with 22 additions and 14 deletions
|
@ -234,9 +234,11 @@ void HTMLOptionElement::inserted()
|
|||
// If insertedNode's parent is a select element,
|
||||
// or insertedNode's parent is an optgroup element whose parent is a select element,
|
||||
// then run that select element's selectedness setting algorithm.
|
||||
if (auto select_element = owner_select_element())
|
||||
if (auto select_element = owner_select_element()) {
|
||||
if (!select_element->can_skip_selectedness_update_for_inserted_option(*this))
|
||||
select_element->update_selectedness();
|
||||
}
|
||||
}
|
||||
|
||||
void HTMLOptionElement::removed_from(Node* old_parent, Node& old_root)
|
||||
{
|
||||
|
|
|
@ -293,15 +293,9 @@ i32 HTMLSelectElement::default_tab_index_value() const
|
|||
return 0;
|
||||
}
|
||||
|
||||
bool HTMLSelectElement::can_skip_children_changed_selectedness_update(ChildrenChangedMetadata const& metadata) const
|
||||
bool HTMLSelectElement::can_skip_selectedness_update_for_inserted_option(HTMLOptionElement const& option) const
|
||||
{
|
||||
// If the following criteria are met, there is no need to re-run the selectedness algorithm.
|
||||
// FIXME: We can tighten up these conditions and skip even more work!
|
||||
if (metadata.type != ChildrenChangedMetadata::Type::Inserted)
|
||||
return false;
|
||||
|
||||
if (auto* option = as_if<HTMLOptionElement>(*metadata.node)) {
|
||||
if (option->selected())
|
||||
if (option.selected())
|
||||
return false;
|
||||
|
||||
if (m_cached_number_of_selected_options >= 2)
|
||||
|
@ -313,6 +307,16 @@ bool HTMLSelectElement::can_skip_children_changed_selectedness_update(ChildrenCh
|
|||
return true;
|
||||
}
|
||||
|
||||
bool HTMLSelectElement::can_skip_children_changed_selectedness_update(ChildrenChangedMetadata const& metadata) const
|
||||
{
|
||||
// If the following criteria are met, there is no need to re-run the selectedness algorithm.
|
||||
// FIXME: We can tighten up these conditions and skip even more work!
|
||||
if (metadata.type != ChildrenChangedMetadata::Type::Inserted)
|
||||
return false;
|
||||
|
||||
if (auto* option = as_if<HTMLOptionElement>(*metadata.node))
|
||||
return can_skip_selectedness_update_for_inserted_option(*option);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -98,6 +98,8 @@ public:
|
|||
|
||||
void update_inner_text_element(Badge<HTMLOptionElement>);
|
||||
|
||||
bool can_skip_selectedness_update_for_inserted_option(HTMLOptionElement const&) const;
|
||||
|
||||
private:
|
||||
HTMLSelectElement(DOM::Document&, DOM::QualifiedName);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue