1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 22:07:35 +00:00

AK: Combine SinglyLinkedList and SinglyLinkedListWithCount

Using policy based design `SinglyLinkedList` and
`SinglyLinkedListWithCount` can be combined into one class which takes
a policy to determine how to keep track of the size of the list. The
default policy is to use list iteration to count the items in the list
each time. The `WithCount` form is a different policy which tracks the
size, but comes with the overhead of storing the count and
incrementing/decrementing on each modification.

This model is extensible to have other forms of counting by
implementing only a new policy instead of implementing a totally new
type.
This commit is contained in:
Lenny Maiorani 2022-12-17 18:06:29 -07:00 committed by Sam Atkins
parent 0105600120
commit e0ab7763da
6 changed files with 183 additions and 156 deletions

View file

@ -7,7 +7,7 @@
#pragma once
#include <AK/HashMap.h>
#include <AK/SinglyLinkedListWithCount.h>
#include <AK/SinglyLinkedList.h>
#include <Kernel/DoubleBuffer.h>
#include <Kernel/KBuffer.h>
#include <Kernel/Locking/MutexProtected.h>
@ -116,7 +116,7 @@ private:
OwnPtr<KBuffer> data;
};
SinglyLinkedListWithCount<ReceivedPacket> m_receive_queue;
SinglyLinkedList<ReceivedPacket, CountingSizeCalculationPolicy> m_receive_queue;
OwnPtr<DoubleBuffer> m_receive_buffer;