mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 03:17:34 +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
10 changed files with 48 additions and 29 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -69,7 +69,7 @@ String Text::render_to_html() const
|
|||
{ "b", &Style::strong },
|
||||
{ "code", &Style::code }
|
||||
};
|
||||
auto it = open_tags.find([&](const String& open_tag) {
|
||||
auto it = open_tags.find_if([&](const String& open_tag) {
|
||||
if (open_tag == "a" && current_style.href != span.style.href)
|
||||
return true;
|
||||
if (open_tag == "img" && current_style.img != span.style.img)
|
||||
|
|
|
@ -398,7 +398,7 @@ ssize_t TLSv12::handle_payload(ReadonlyBytes vbuffer)
|
|||
}
|
||||
payload_res = handle_certificate(buffer.slice(1, payload_size));
|
||||
if (m_context.certificates.size()) {
|
||||
auto it = m_context.certificates.find([&](auto& cert) { return cert.is_valid(); });
|
||||
auto it = m_context.certificates.find_if([](const auto& cert) { return cert.is_valid(); });
|
||||
|
||||
if (it.is_end()) {
|
||||
// no valid certificates
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue