mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 01:20:25 +00:00
0cea80218d
Previously we would not run destructors for items in a CircularQueue, which would lead to memory leaks. This patch fixes that, and also adds a basic unit test for the class.
25 lines
490 B
C++
25 lines
490 B
C++
#pragma once
|
|
|
|
#include <AK/Assertions.h>
|
|
#include <AK/CircularQueue.h>
|
|
#include <AK/Types.h>
|
|
|
|
namespace AK {
|
|
|
|
template<typename T, int Capacity>
|
|
class CircularDeque : public CircularQueue<T, Capacity> {
|
|
public:
|
|
T dequeue_end()
|
|
{
|
|
ASSERT(!this->is_empty());
|
|
auto& slot = this->elements()[(this->m_head + this->m_size - 1) % Capacity];
|
|
T value = move(slot);
|
|
slot.~T();
|
|
this->m_size--;
|
|
return value;
|
|
}
|
|
};
|
|
|
|
}
|
|
|
|
using AK::CircularDeque;
|