mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-26 20:55:35 +03:00
AK+LibGUI: Pass predicate to *_matching() methods by const reference
This commit is contained in:
parent
6ed2ded77c
commit
a0a4d169f4
Notes:
sideshowbarker
2024-07-17 11:08:20 +09:00
Author: https://github.com/obyknovenius Commit: https://github.com/SerenityOS/serenity/commit/a0a4d169f4 Pull-request: https://github.com/SerenityOS/serenity/pull/13641 Reviewed-by: https://github.com/ldm5180 ✅
@ -77,7 +77,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename TUnaryPredicate>
|
template<typename TUnaryPredicate>
|
||||||
bool remove_all_matching(TUnaryPredicate predicate)
|
bool remove_all_matching(TUnaryPredicate const& predicate)
|
||||||
{
|
{
|
||||||
return m_table.template remove_all_matching([&](auto& entry) {
|
return m_table.template remove_all_matching([&](auto& entry) {
|
||||||
return predicate(entry.key, entry.value);
|
return predicate(entry.key, entry.value);
|
||||||
|
@ -422,7 +422,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename TUnaryPredicate>
|
template<typename TUnaryPredicate>
|
||||||
bool remove_all_matching(TUnaryPredicate predicate)
|
bool remove_all_matching(TUnaryPredicate const& predicate)
|
||||||
{
|
{
|
||||||
size_t removed_count = 0;
|
size_t removed_count = 0;
|
||||||
for (size_t i = 0; i < m_capacity; ++i) {
|
for (size_t i = 0; i < m_capacity; ++i) {
|
||||||
|
14
AK/Vector.h
14
AK/Vector.h
@ -163,7 +163,7 @@ public:
|
|||||||
VisibleType& last() { return at(size() - 1); }
|
VisibleType& last() { return at(size() - 1); }
|
||||||
|
|
||||||
template<typename TUnaryPredicate>
|
template<typename TUnaryPredicate>
|
||||||
Optional<VisibleType&> first_matching(TUnaryPredicate predicate) requires(!contains_reference)
|
Optional<VisibleType&> first_matching(TUnaryPredicate const& predicate) requires(!contains_reference)
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < size(); ++i) {
|
for (size_t i = 0; i < size(); ++i) {
|
||||||
if (predicate(at(i))) {
|
if (predicate(at(i))) {
|
||||||
@ -174,7 +174,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename TUnaryPredicate>
|
template<typename TUnaryPredicate>
|
||||||
Optional<VisibleType const&> first_matching(TUnaryPredicate predicate) const requires(!contains_reference)
|
Optional<VisibleType const&> first_matching(TUnaryPredicate const& predicate) const requires(!contains_reference)
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < size(); ++i) {
|
for (size_t i = 0; i < size(); ++i) {
|
||||||
if (predicate(at(i))) {
|
if (predicate(at(i))) {
|
||||||
@ -185,7 +185,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename TUnaryPredicate>
|
template<typename TUnaryPredicate>
|
||||||
Optional<VisibleType&> last_matching(TUnaryPredicate predicate) requires(!contains_reference)
|
Optional<VisibleType&> last_matching(TUnaryPredicate const& predicate) requires(!contains_reference)
|
||||||
{
|
{
|
||||||
for (ssize_t i = size() - 1; i >= 0; --i) {
|
for (ssize_t i = size() - 1; i >= 0; --i) {
|
||||||
if (predicate(at(i))) {
|
if (predicate(at(i))) {
|
||||||
@ -233,7 +233,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename TUnaryPredicate, typename U = T>
|
template<typename TUnaryPredicate, typename U = T>
|
||||||
void insert_before_matching(U&& value, TUnaryPredicate predicate, size_t first_index = 0, size_t* inserted_index = nullptr) requires(CanBePlacedInsideVector<U>)
|
void insert_before_matching(U&& value, TUnaryPredicate const& predicate, size_t first_index = 0, size_t* inserted_index = nullptr) requires(CanBePlacedInsideVector<U>)
|
||||||
{
|
{
|
||||||
MUST(try_insert_before_matching(forward<U>(value), predicate, first_index, inserted_index));
|
MUST(try_insert_before_matching(forward<U>(value), predicate, first_index, inserted_index));
|
||||||
}
|
}
|
||||||
@ -415,7 +415,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename TUnaryPredicate>
|
template<typename TUnaryPredicate>
|
||||||
bool remove_first_matching(TUnaryPredicate predicate)
|
bool remove_first_matching(TUnaryPredicate const& predicate)
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < size(); ++i) {
|
for (size_t i = 0; i < size(); ++i) {
|
||||||
if (predicate(at(i))) {
|
if (predicate(at(i))) {
|
||||||
@ -427,7 +427,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename TUnaryPredicate>
|
template<typename TUnaryPredicate>
|
||||||
bool remove_all_matching(TUnaryPredicate predicate)
|
bool remove_all_matching(TUnaryPredicate const& predicate)
|
||||||
{
|
{
|
||||||
bool something_was_removed = false;
|
bool something_was_removed = false;
|
||||||
for (size_t i = 0; i < size();) {
|
for (size_t i = 0; i < size();) {
|
||||||
@ -507,7 +507,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename TUnaryPredicate, typename U = T>
|
template<typename TUnaryPredicate, typename U = T>
|
||||||
ErrorOr<void> try_insert_before_matching(U&& value, TUnaryPredicate predicate, size_t first_index = 0, size_t* inserted_index = nullptr) requires(CanBePlacedInsideVector<U>)
|
ErrorOr<void> try_insert_before_matching(U&& value, TUnaryPredicate const& predicate, size_t first_index = 0, size_t* inserted_index = nullptr) requires(CanBePlacedInsideVector<U>)
|
||||||
{
|
{
|
||||||
for (size_t i = first_index; i < size(); ++i) {
|
for (size_t i = first_index; i < size(); ++i) {
|
||||||
if (predicate(at(i))) {
|
if (predicate(at(i))) {
|
||||||
|
@ -10,9 +10,9 @@
|
|||||||
|
|
||||||
namespace GUI {
|
namespace GUI {
|
||||||
|
|
||||||
void ModelSelection::remove_all_matching(Function<bool(ModelIndex const&)> filter)
|
void ModelSelection::remove_all_matching(Function<bool(ModelIndex const&)> const& filter)
|
||||||
{
|
{
|
||||||
if (m_indices.remove_all_matching([&](ModelIndex const& index) { return filter(index); }))
|
if (m_indices.remove_all_matching(filter))
|
||||||
notify_selection_changed();
|
notify_selection_changed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ public:
|
|||||||
return *m_indices.begin();
|
return *m_indices.begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
void remove_all_matching(Function<bool(ModelIndex const&)> filter);
|
void remove_all_matching(Function<bool(ModelIndex const&)> const& filter);
|
||||||
|
|
||||||
template<typename Function>
|
template<typename Function>
|
||||||
void change_from_model(Badge<SortingProxyModel>, Function f)
|
void change_from_model(Badge<SortingProxyModel>, Function f)
|
||||||
|
Loading…
Reference in New Issue
Block a user