mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-28 05:35:52 +03:00
AK: Make all DoublyLinkedList search methods use Traits<T>::equals (#3404)
This commit is contained in:
parent
02b3cb8123
commit
fad0c8e712
Notes:
sideshowbarker
2024-07-19 02:54:55 +09:00
Author: https://github.com/tryfinally Commit: https://github.com/SerenityOS/serenity/commit/fad0c8e712a Pull-request: https://github.com/SerenityOS/serenity/pull/3404
@ -74,7 +74,7 @@ private:
|
||||
};
|
||||
|
||||
public:
|
||||
DoublyLinkedList() {}
|
||||
DoublyLinkedList() { }
|
||||
~DoublyLinkedList() { clear(); }
|
||||
|
||||
bool is_empty() const { return !head(); }
|
||||
@ -133,11 +133,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_node(value) != nullptr;
|
||||
}
|
||||
|
||||
using Iterator = DoublyLinkedListIterator<DoublyLinkedList, T>;
|
||||
@ -152,19 +148,17 @@ public:
|
||||
|
||||
ConstIterator find(const T& value) const
|
||||
{
|
||||
for (auto* node = m_head; node; node = node->next) {
|
||||
if (Traits<T>::equals(node->value, value))
|
||||
return ConstIterator(node);
|
||||
}
|
||||
Node* node = find_node(value);
|
||||
if (node)
|
||||
return ConstIterator(node);
|
||||
return end();
|
||||
}
|
||||
|
||||
Iterator find(const T& value)
|
||||
{
|
||||
for (auto* node = m_head; node; node = node->next) {
|
||||
if (Traits<T>::equals(node->value, value))
|
||||
return Iterator(node);
|
||||
}
|
||||
Node* node = find_node(value);
|
||||
if (node)
|
||||
return Iterator(node);
|
||||
return end();
|
||||
}
|
||||
|
||||
@ -220,6 +214,15 @@ private:
|
||||
m_head = node;
|
||||
}
|
||||
|
||||
Node* find_node(const T& value) const
|
||||
{
|
||||
for (auto* node = m_head; node; node = node->next) {
|
||||
if (Traits<T>::equals(node->value, value))
|
||||
return node;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Node* head() { return m_head; }
|
||||
const Node* head() const { return m_head; }
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user