diff options
author | Muhammad Zahalqa <m@tryfinally.com> | 2020-09-05 15:17:14 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-05 14:17:14 +0200 |
commit | fad0c8e712a9492f402f7a1676e372b17a3d9d7f (patch) | |
tree | cab29b0374e802c6fce04a6150cb89d7f598d832 | |
parent | 02b3cb812367266da673edda30c3393fa25e2e52 (diff) | |
download | serenity-fad0c8e712a9492f402f7a1676e372b17a3d9d7f.zip |
AK: Make all DoublyLinkedList search methods use Traits<T>::equals (#3404)
-rw-r--r-- | AK/DoublyLinkedList.h | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/AK/DoublyLinkedList.h b/AK/DoublyLinkedList.h index 6fcc869483..9990b9ce77 100644 --- a/AK/DoublyLinkedList.h +++ b/AK/DoublyLinkedList.h @@ -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; } |