mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-13 11:42:38 +03: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.
26 lines
490 B
C++
26 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;
|