mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-12-08 06:09:58 +00:00
AK: Add some higher-level operations to DoublyLinkedList<T>
This also adds a node cache as allocation/deallocation was showing up in my profiles; disabled by default to keep the old behaviour.
This commit is contained in:
parent
dc67f0ad4e
commit
bf4c436ef3
Notes:
github-actions[bot]
2025-08-08 10:56:47 +00:00
Author: https://github.com/alimpfard
Commit: bf4c436ef3
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5060
Reviewed-by: https://github.com/Hendiadyoin1
Reviewed-by: https://github.com/R-Goc
Reviewed-by: https://github.com/awesomekling
Reviewed-by: https://github.com/gmta
3 changed files with 171 additions and 15 deletions
|
|
@ -41,3 +41,50 @@ TEST_CASE(should_find_const)
|
|||
|
||||
EXPECT_EQ(sut.end(), sut.find(42));
|
||||
}
|
||||
|
||||
TEST_CASE(take_first)
|
||||
{
|
||||
auto sut = make_list();
|
||||
|
||||
EXPECT_EQ(0, sut.take_first());
|
||||
EXPECT_EQ(1, sut.first());
|
||||
EXPECT_EQ(9, sut.last());
|
||||
EXPECT_EQ(9u, sut.size());
|
||||
}
|
||||
|
||||
TEST_CASE(take_last)
|
||||
{
|
||||
auto sut = make_list();
|
||||
|
||||
EXPECT_EQ(9, sut.take_last());
|
||||
EXPECT_EQ(8, sut.last());
|
||||
EXPECT_EQ(0, sut.first());
|
||||
EXPECT_EQ(9u, sut.size());
|
||||
}
|
||||
|
||||
TEST_CASE(take_last_all)
|
||||
{
|
||||
auto sut = make_list();
|
||||
|
||||
for (int i = 0; i < 10; ++i)
|
||||
EXPECT_EQ(9 - i, sut.take_last());
|
||||
|
||||
EXPECT_EQ(sut.size(), 0u);
|
||||
}
|
||||
|
||||
TEST_CASE(basic_node_cache)
|
||||
{
|
||||
// FIXME: Add more comprehensive tests.
|
||||
DoublyLinkedList<int, 2> list;
|
||||
list.append(0);
|
||||
list.append(1);
|
||||
|
||||
Vector<void*> seen_ptrs;
|
||||
for (auto& entry : list)
|
||||
seen_ptrs.append(&entry);
|
||||
|
||||
list.take_last();
|
||||
|
||||
list.append(2);
|
||||
EXPECT(seen_ptrs.contains_slow(&list.last())); // node cache should have reused the last node
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue