AK: Add IntrusiveList::size_slow() to match InlineLinkedList

The functionality is needed to replace InlineLinkedList with
IntrusiveList in the Kernel Process class.
This commit is contained in:
Brian Gianforcaro 2021-06-06 14:13:10 -07:00 committed by Andreas Kling
parent 3dfd450f2d
commit f5e04759cc
Notes: sideshowbarker 2024-07-18 12:43:36 +09:00
2 changed files with 13 additions and 0 deletions

View File

@ -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<T, Container, member>::is_empty() const
return m_storage.m_first == nullptr;
}
template<class T, typename Container, IntrusiveListNode<T, Container> T::*member>
inline size_t IntrusiveList<T, Container, member>::size_slow() const
{
size_t size = 0;
auto it_end = end();
for (auto it = begin(); it != it_end; ++it) {
++size;
}
return size;
}
template<class T, typename Container, IntrusiveListNode<T, Container> T::*member>
inline void IntrusiveList<T, Container, member>::append(T& n)
{

View File

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