LibWeb: Cache name->element mappings in HTMLCollection

This makes https://wpt.fyi/ load today instead of tomorrow, although
there's a lot of room for improvement still.
This commit is contained in:
Andreas Kling 2024-07-25 07:49:41 +02:00 committed by Andreas Kling
commit 4d78c66b3d
Notes: github-actions[bot] 2024-07-25 11:12:56 +00:00
4 changed files with 48 additions and 31 deletions

View file

@ -43,6 +43,7 @@ public:
virtual WebIDL::ExceptionOr<JS::Value> item_value(size_t index) const override;
virtual WebIDL::ExceptionOr<JS::Value> named_item_value(FlyString const& name) const override;
virtual Vector<FlyString> supported_property_names() const override;
virtual bool is_supported_property_name(FlyString const&) const override;
virtual bool is_supported_property_index(u32) const override;
protected:
@ -57,9 +58,11 @@ private:
virtual void visit_edges(Cell::Visitor&) override;
void update_cache_if_needed() const;
void update_name_to_element_mappings_if_needed() const;
mutable u64 m_cached_dom_tree_version { 0 };
mutable Vector<JS::NonnullGCPtr<Element>> m_cached_elements;
mutable OwnPtr<HashMap<FlyString, JS::NonnullGCPtr<Element>>> m_cached_name_to_element_mappings;
JS::NonnullGCPtr<ParentNode> m_root;
Function<bool(Element const&)> m_filter;