mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-15 07:32:52 +00:00
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:
parent
4333a9a8d6
commit
f99d1d3bd7
Notes:
sideshowbarker
2024-07-18 23:56:20 +09:00
Author: https://github.com/ldm5180
Commit: f99d1d3bd7
Pull-request: https://github.com/SerenityOS/serenity/pull/4894
Reviewed-by: https://github.com/awesomekling
Reviewed-by: https://github.com/linusg
10 changed files with 48 additions and 29 deletions
|
@ -80,7 +80,7 @@ static String variable_value_as_string(const Debug::DebugInfo::VariableInfo& var
|
|||
if (variable.is_enum_type()) {
|
||||
auto value = Debugger::the().session()->peek((u32*)variable_address);
|
||||
ASSERT(value.has_value());
|
||||
auto it = variable.type->members.find([enumerator_value = value.value()](auto& enumerator) {
|
||||
auto it = variable.type->members.find_if([&enumerator_value = value.value()](const auto& enumerator) {
|
||||
return enumerator->constant_data.as_u32 == enumerator_value;
|
||||
});
|
||||
ASSERT(!it.is_end());
|
||||
|
@ -116,7 +116,7 @@ static Optional<u32> string_to_variable_value(const StringView& string_value, co
|
|||
if (string_value.starts_with(prefix_string))
|
||||
string_to_use = string_value.substring_view(prefix_string.length(), string_value.length() - prefix_string.length());
|
||||
|
||||
auto it = variable.type->members.find([string_to_use](auto& enumerator) {
|
||||
auto it = variable.type->members.find_if([string_to_use](const auto& enumerator) {
|
||||
return enumerator->name == string_to_use;
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue