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`.
This commit is contained in:
Lenny Maiorani 2020-12-23 11:35:20 -07:00 committed by Andreas Kling
parent 4333a9a8d6
commit f99d1d3bd7
Notes: sideshowbarker 2024-07-18 23:56:20 +09:00
10 changed files with 48 additions and 29 deletions

View file

@ -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()) {