From f5e04759cc0e68adb6910d23d95d5f64b85b26f3 Mon Sep 17 00:00:00 2001 From: Brian Gianforcaro Date: Sun, 6 Jun 2021 14:13:10 -0700 Subject: [PATCH] AK: Add IntrusiveList::size_slow() to match InlineLinkedList The functionality is needed to replace InlineLinkedList with IntrusiveList in the Kernel Process class. --- AK/IntrusiveList.h | 12 ++++++++++++ Tests/AK/TestIntrusiveList.cpp | 1 + 2 files changed, 13 insertions(+) diff --git a/AK/IntrusiveList.h b/AK/IntrusiveList.h index deadad169de..a5cdc77bbe7 100644 --- a/AK/IntrusiveList.h +++ b/AK/IntrusiveList.h @@ -51,6 +51,7 @@ public: void clear(); [[nodiscard]] bool is_empty() const; + [[nodiscard]] size_t size_slow() const; void append(T& n); void prepend(T& n); void remove(T& n); @@ -214,6 +215,17 @@ inline bool IntrusiveList::is_empty() const return m_storage.m_first == nullptr; } +template T::*member> +inline size_t IntrusiveList::size_slow() const +{ + size_t size = 0; + auto it_end = end(); + for (auto it = begin(); it != it_end; ++it) { + ++size; + } + return size; +} + template T::*member> inline void IntrusiveList::append(T& n) { diff --git a/Tests/AK/TestIntrusiveList.cpp b/Tests/AK/TestIntrusiveList.cpp index 005642a9b6d..84f1d9f2c20 100644 --- a/Tests/AK/TestIntrusiveList.cpp +++ b/Tests/AK/TestIntrusiveList.cpp @@ -47,6 +47,7 @@ TEST_CASE(enumeration) actual_size++; } EXPECT_EQ(expected_size, actual_size); + EXPECT_EQ(expected_size, list.size_slow()); size_t reverse_actual_size = 0; for (auto it = list.rbegin(); it != list.rend(); ++it) {