From c322603c4201ab680923929ca8dd5d0056202cf8 Mon Sep 17 00:00:00 2001 From: Tim Ledbetter Date: Sun, 24 Nov 2024 16:46:42 +0000 Subject: [PATCH] LibWeb: Avoid Vector filtering when performing find in page queries --- Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp | 2 +- Libraries/LibWeb/HTML/EventLoop/EventLoop.h | 3 +-- Libraries/LibWeb/Page/Page.cpp | 8 +++----- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp b/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp index 603119593bd..432a088b608 100644 --- a/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp +++ b/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp @@ -513,7 +513,7 @@ void EventLoop::perform_a_microtask_checkpoint() // FIXME: 8. Record timing info for microtask checkpoint. } -Vector> EventLoop::documents_in_this_event_loop_matching(auto callback) const +Vector> EventLoop::documents_in_this_event_loop_matching(Function callback) const { Vector> documents; for (auto& document : m_documents) { diff --git a/Libraries/LibWeb/HTML/EventLoop/EventLoop.h b/Libraries/LibWeb/HTML/EventLoop/EventLoop.h index 2e27eaa142e..54f2b3c1ba7 100644 --- a/Libraries/LibWeb/HTML/EventLoop/EventLoop.h +++ b/Libraries/LibWeb/HTML/EventLoop/EventLoop.h @@ -73,6 +73,7 @@ public: void unregister_document(Badge, DOM::Document&); Vector> documents_in_this_event_loop() const; + [[nodiscard]] Vector> documents_in_this_event_loop_matching(Function callback) const; Vector> same_loop_windows() const; @@ -95,8 +96,6 @@ private: virtual void visit_edges(Visitor&) override; - [[nodiscard]] Vector> documents_in_this_event_loop_matching(auto callback) const; - void update_the_rendering(); Type m_type { Type::Window }; diff --git a/Libraries/LibWeb/Page/Page.cpp b/Libraries/LibWeb/Page/Page.cpp index 768475e4bc3..13257b39d9f 100644 --- a/Libraries/LibWeb/Page/Page.cpp +++ b/Libraries/LibWeb/Page/Page.cpp @@ -569,11 +569,9 @@ Vector> Page::documents_in_active_window() const if (!top_level_traversable_is_initialized()) return {}; - auto documents = HTML::main_thread_event_loop().documents_in_this_event_loop(); - for (ssize_t i = documents.size() - 1; i >= 0; --i) { - if (documents[i]->window() != top_level_traversable()->active_window()) - documents.remove(i); - } + auto documents = HTML::main_thread_event_loop().documents_in_this_event_loop_matching([&](auto& document) { + return document.window() == top_level_traversable()->active_window(); + }); return documents; }