summaryrefslogtreecommitdiff
path: root/Services
diff options
context:
space:
mode:
authorLenny Maiorani <lenny@colorado.edu>2020-12-23 11:35:20 -0700
committerAndreas Kling <kling@serenityos.org>2021-01-11 19:45:05 +0100
commitf99d1d3bd7d6f752c490c358217c360b7e0bda80 (patch)
treef06dfaaec5128b6a3844b29f316e0ee20235caf0 /Services
parent4333a9a8d6d9b98e0923e09e06deb41ee5bcd5b7 (diff)
downloadserenity-f99d1d3bd7d6f752c490c358217c360b7e0bda80.zip
Vector: Implement `find`, `find_if`, `find_first_matching` in terms of `AK::find*`
Problem: - The implementation of `find` is coupled to the implementation of `Vector`. - `Vector::find` takes the predicate by value which might be expensive. Solution: - Decouple the implementation of `find` from `Vector` by using a generic `find` algorithm. - Change the name of `find` with a predicate to `find_if` so that a binding reference can be used and the predicate can be forwarded to avoid copies. - Change all the `find(pred)` call sites to use `find_if`.
Diffstat (limited to 'Services')
-rw-r--r--Services/WindowServer/MenuManager.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/Services/WindowServer/MenuManager.cpp b/Services/WindowServer/MenuManager.cpp
index 28639db98f..ba2ba789f9 100644
--- a/Services/WindowServer/MenuManager.cpp
+++ b/Services/WindowServer/MenuManager.cpp
@@ -162,7 +162,7 @@ void MenuManager::event(Core::Event& event)
if (event.type() == Event::KeyDown) {
if (key_event.key() == Key_Left) {
- auto it = m_open_menu_stack.find([&](auto& other) { return m_current_menu == other.ptr(); });
+ auto it = m_open_menu_stack.find_if([&](const auto& other) { return m_current_menu == other.ptr(); });
ASSERT(!it.is_end());
// Going "back" a menu should be the previous menu in the stack
@@ -390,7 +390,7 @@ void MenuManager::open_menu(Menu& menu, bool as_current_menu)
menu.menu_window()->set_visible(true);
}
- if (m_open_menu_stack.find([&menu](auto& other) { return &menu == other.ptr(); }).is_end())
+ if (m_open_menu_stack.find_if([&menu](auto& other) { return &menu == other.ptr(); }).is_end())
m_open_menu_stack.append(menu);
if (as_current_menu || !current_menu()) {