mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
AK: SinglyLinkedList use Traits<T>::equals in find
Use Traits<T>::equals for equality checking in search functions instead of operator==
This commit is contained in:
parent
f1a6884a51
commit
ad3e6ef344
Notes:
sideshowbarker
2024-07-19 02:51:52 +09:00
Author: https://github.com/tryfinally Commit: https://github.com/SerenityOS/serenity/commit/ad3e6ef3444 Pull-request: https://github.com/SerenityOS/serenity/pull/3412
1 changed files with 6 additions and 9 deletions
|
@ -28,6 +28,7 @@
|
|||
|
||||
#include <AK/Assertions.h>
|
||||
#include <AK/StdLibExtras.h>
|
||||
#include <AK/Traits.h>
|
||||
#include <AK/Types.h>
|
||||
|
||||
namespace AK {
|
||||
|
@ -35,7 +36,7 @@ namespace AK {
|
|||
template<typename ListType, typename ElementType>
|
||||
class SinglyLinkedListIterator {
|
||||
public:
|
||||
SinglyLinkedListIterator() {}
|
||||
SinglyLinkedListIterator() { }
|
||||
bool operator!=(const SinglyLinkedListIterator& other) const { return m_node != other.m_node; }
|
||||
SinglyLinkedListIterator& operator++()
|
||||
{
|
||||
|
@ -76,7 +77,7 @@ private:
|
|||
};
|
||||
|
||||
public:
|
||||
SinglyLinkedList() {}
|
||||
SinglyLinkedList() { }
|
||||
~SinglyLinkedList() { clear(); }
|
||||
|
||||
bool is_empty() const { return !head(); }
|
||||
|
@ -152,11 +153,7 @@ public:
|
|||
|
||||
bool contains_slow(const T& value) const
|
||||
{
|
||||
for (auto* node = m_head; node; node = node->next) {
|
||||
if (node->value == value)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return find(value) != end();
|
||||
}
|
||||
|
||||
using Iterator = SinglyLinkedListIterator<SinglyLinkedList, T>;
|
||||
|
@ -195,12 +192,12 @@ public:
|
|||
|
||||
ConstIterator find(const T& value) const
|
||||
{
|
||||
return find([&](auto& other) { return value == other; });
|
||||
return find([&](auto& other) { return Traits<T>::equals(value, other); });
|
||||
}
|
||||
|
||||
Iterator find(const T& value)
|
||||
{
|
||||
return find([&](auto& other) { return value == other; });
|
||||
return find([&](auto& other) { return Traits<T>::equals(value, other); });
|
||||
}
|
||||
|
||||
void remove(Iterator iterator)
|
||||
|
|
Loading…
Reference in a new issue