mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-22 17:28:30 +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:
committed by
Andrew Kaster
parent
075c7ea63e
commit
ebd6d49415
@@ -293,6 +293,20 @@ i32 HTMLSelectElement::default_tab_index_value() const
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool HTMLSelectElement::can_skip_selectedness_update_for_inserted_option(HTMLOptionElement const& option) const
|
||||
{
|
||||
if (option.selected())
|
||||
return false;
|
||||
|
||||
if (m_cached_number_of_selected_options >= 2)
|
||||
return false;
|
||||
|
||||
if (display_size() == 1 && m_cached_number_of_selected_options == 0)
|
||||
return false;
|
||||
|
||||
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.
|
||||
@@ -300,18 +314,8 @@ bool HTMLSelectElement::can_skip_children_changed_selectedness_update(ChildrenCh
|
||||
if (metadata.type != ChildrenChangedMetadata::Type::Inserted)
|
||||
return false;
|
||||
|
||||
if (auto* option = as_if<HTMLOptionElement>(*metadata.node)) {
|
||||
if (option->selected())
|
||||
return false;
|
||||
|
||||
if (m_cached_number_of_selected_options >= 2)
|
||||
return false;
|
||||
|
||||
if (display_size() == 1 && m_cached_number_of_selected_options == 0)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
if (auto* option = as_if<HTMLOptionElement>(*metadata.node))
|
||||
return can_skip_selectedness_update_for_inserted_option(*option);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user