LibWeb/HTML: Add a cache for the list of Options for HTMLSelectElement

This is still called _way_ too often, and we need to be much smarter
about when this needs to run. But we get two wins from this very
naive implementation:

  1. There is a inner text setter nested within the selectedness
     steps uses this list of elements. This saves us building
     up a list of elements again within these steps.
  2. More importantly, it caches the number of selected elements.
     This already allows us to skip a minor amount of work iterating
     over the children again. But in future commits, this will serve
     as one of the criteria for skipping running the selectedness
     algorithm altogether for certain cases, which is a very big win.

A example future idea might be to append to this list directly when
something like appendChild is run instead of iterating over all of
the children again. But that's left as future work.
This commit is contained in:
Shannon Booth 2025-01-26 15:16:07 +13:00 committed by Andrew Kaster
parent c647ac407d
commit 5b6b4d93a3
Notes: github-actions[bot] 2025-01-30 20:57:07 +00:00
2 changed files with 48 additions and 34 deletions

View file

@ -111,6 +111,7 @@ private:
virtual void children_changed() override;
void update_cached_list_of_options() const;
void show_the_picker_if_applicable();
void create_shadow_tree_if_needed();
@ -119,6 +120,9 @@ private:
u32 display_size() const;
mutable Vector<GC::Ref<HTMLOptionElement>> m_cached_list_of_options;
mutable size_t m_cached_number_of_selected_options { 0 };
GC::Ptr<HTMLOptionsCollection> m_options;
GC::Ptr<DOM::HTMLCollection> m_selected_options;
bool m_is_open { false };