mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-29 14:14:45 +03:00
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:
parent
3dfd450f2d
commit
f5e04759cc
Notes:
sideshowbarker
2024-07-18 12:43:36 +09:00
Author: https://github.com/bgianfo Commit: https://github.com/SerenityOS/serenity/commit/f5e04759cc0 Pull-request: https://github.com/SerenityOS/serenity/pull/7859
@ -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)
|
||||
{
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user