diff options
author | Lenny Maiorani <lenny@colorado.edu> | 2020-12-23 11:35:20 -0700 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-01-11 19:45:05 +0100 |
commit | f99d1d3bd7d6f752c490c358217c360b7e0bda80 (patch) | |
tree | f06dfaaec5128b6a3844b29f316e0ee20235caf0 /Libraries/LibCore | |
parent | 4333a9a8d6d9b98e0923e09e06deb41ee5bcd5b7 (diff) | |
download | serenity-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 'Libraries/LibCore')
-rw-r--r-- | Libraries/LibCore/ArgsParser.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/Libraries/LibCore/ArgsParser.cpp b/Libraries/LibCore/ArgsParser.cpp index 16583b9012..121272e38b 100644 --- a/Libraries/LibCore/ArgsParser.cpp +++ b/Libraries/LibCore/ArgsParser.cpp @@ -109,7 +109,7 @@ bool ArgsParser::parse(int argc, char** argv, bool exit_on_failure) index_of_found_long_option = -1; } else { // It was a short option, look it up. - auto it = m_options.find([c](auto& opt) { return c == opt.short_name; }); + auto it = m_options.find_if([c](auto& opt) { return c == opt.short_name; }); ASSERT(!it.is_end()); found_option = &*it; } |