mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 06:37:44 +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
|
@ -187,7 +187,7 @@ void Cell::reference_from(Cell* other)
|
|||
if (!other || other == this)
|
||||
return;
|
||||
|
||||
if (!m_referencing_cells.find([other](auto& ptr) { return ptr.ptr() == other; }).is_end())
|
||||
if (!m_referencing_cells.find_if([other](const auto& ptr) { return ptr.ptr() == other; }).is_end())
|
||||
return;
|
||||
|
||||
m_referencing_cells.append(other->make_weak_ptr());
|
||||
|
|
|
@ -244,7 +244,7 @@ XSV::Field XSV::read_one_unquoted_field()
|
|||
StringView XSV::Row::operator[](StringView name) const
|
||||
{
|
||||
ASSERT(!m_xsv.m_names.is_empty());
|
||||
auto it = m_xsv.m_names.find([&](auto&& entry) { return name == entry; });
|
||||
auto it = m_xsv.m_names.find_if([&](const auto& entry) { return name == entry; });
|
||||
ASSERT(!it.is_end());
|
||||
|
||||
return (*this)[it.index()];
|
||||
|
|
|
@ -182,7 +182,7 @@ void DevicesModel::update()
|
|||
unsigned _major = major(statbuf.st_rdev);
|
||||
unsigned _minor = minor(statbuf.st_rdev);
|
||||
|
||||
auto it = m_devices.find([_major, _minor](auto& device_info) {
|
||||
auto it = m_devices.find_if([_major, _minor](const auto& device_info) {
|
||||
return device_info.major == _major && device_info.minor == _minor;
|
||||
});
|
||||
if (it != m_devices.end()) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue