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) {