From f99d1d3bd7d6f752c490c358217c360b7e0bda80 Mon Sep 17 00:00:00 2001 From: Lenny Maiorani Date: Wed, 23 Dec 2020 11:35:20 -0700 Subject: 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`. --- Libraries/LibTLS/ClientHandshake.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Libraries/LibTLS') diff --git a/Libraries/LibTLS/ClientHandshake.cpp b/Libraries/LibTLS/ClientHandshake.cpp index 1632bf6a76..b1fbaa2391 100644 --- a/Libraries/LibTLS/ClientHandshake.cpp +++ b/Libraries/LibTLS/ClientHandshake.cpp @@ -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 -- cgit v1.2.3