mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
AK: Use size_t for CircularQueue and CircularDeque
This commit is contained in:
parent
88b9fcb976
commit
7592f9afd5
Notes:
sideshowbarker
2024-07-19 09:12:17 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/7592f9afd5b
5 changed files with 19 additions and 15 deletions
|
@ -32,7 +32,7 @@
|
|||
|
||||
namespace AK {
|
||||
|
||||
template<typename T, int Capacity>
|
||||
template<typename T, size_t Capacity>
|
||||
class CircularDeque : public CircularQueue<T, Capacity> {
|
||||
public:
|
||||
T dequeue_end()
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
|
||||
namespace AK {
|
||||
|
||||
template<typename T, int Capacity>
|
||||
template<typename T, size_t Capacity>
|
||||
class CircularQueue {
|
||||
public:
|
||||
CircularQueue()
|
||||
|
@ -46,7 +46,7 @@ public:
|
|||
|
||||
void clear()
|
||||
{
|
||||
for (int i = 0; i < m_size; ++i)
|
||||
for (size_t i = 0; i < m_size; ++i)
|
||||
elements()[(m_head + i) % Capacity].~T();
|
||||
|
||||
m_head = 0;
|
||||
|
@ -54,9 +54,9 @@ public:
|
|||
}
|
||||
|
||||
bool is_empty() const { return !m_size; }
|
||||
int size() const { return m_size; }
|
||||
size_t size() const { return m_size; }
|
||||
|
||||
int capacity() const { return Capacity; }
|
||||
size_t capacity() const { return Capacity; }
|
||||
|
||||
void enqueue(T&& value)
|
||||
{
|
||||
|
@ -87,7 +87,7 @@ public:
|
|||
return value;
|
||||
}
|
||||
|
||||
const T& at(int index) const { return elements()[(m_head + index) % Capacity]; }
|
||||
const T& at(size_t index) const { return elements()[(m_head + index) % Capacity]; }
|
||||
|
||||
const T& first() const { return at(0); }
|
||||
const T& last() const { return at(size() - 1); }
|
||||
|
@ -107,19 +107,19 @@ public:
|
|||
|
||||
private:
|
||||
friend class CircularQueue;
|
||||
ConstIterator(const CircularQueue& queue, const int index)
|
||||
ConstIterator(const CircularQueue& queue, const size_t index)
|
||||
: m_queue(queue)
|
||||
, m_index(index)
|
||||
{
|
||||
}
|
||||
const CircularQueue& m_queue;
|
||||
int m_index { 0 };
|
||||
size_t m_index { 0 };
|
||||
};
|
||||
|
||||
ConstIterator begin() const { return ConstIterator(*this, m_head); }
|
||||
ConstIterator end() const { return ConstIterator(*this, size()); }
|
||||
|
||||
int head_index() const { return m_head; }
|
||||
size_t head_index() const { return m_head; }
|
||||
|
||||
protected:
|
||||
T* elements() { return reinterpret_cast<T*>(m_storage); }
|
||||
|
@ -127,8 +127,8 @@ protected:
|
|||
|
||||
friend class ConstIterator;
|
||||
alignas(T) u8 m_storage[sizeof(T) * Capacity];
|
||||
int m_size { 0 };
|
||||
int m_head { 0 };
|
||||
size_t m_size { 0 };
|
||||
size_t m_head { 0 };
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -26,6 +26,8 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Types.h>
|
||||
|
||||
namespace AK {
|
||||
|
||||
class Bitmap;
|
||||
|
@ -57,7 +59,7 @@ class DoublyLinkedList;
|
|||
template<typename T>
|
||||
class InlineLinkedList;
|
||||
|
||||
template<typename T, int capacity>
|
||||
template<typename T, size_t capacity>
|
||||
class CircularQueue;
|
||||
|
||||
template<typename T>
|
||||
|
@ -116,8 +118,8 @@ using AK::FixedArray;
|
|||
using AK::Function;
|
||||
using AK::HashMap;
|
||||
using AK::HashTable;
|
||||
using AK::IPv4Address;
|
||||
using AK::InlineLinkedList;
|
||||
using AK::IPv4Address;
|
||||
using AK::JsonArray;
|
||||
using AK::JsonObject;
|
||||
using AK::JsonValue;
|
||||
|
|
|
@ -58,7 +58,7 @@ void GraphWidget::paint_event(GUI::PaintEvent& event)
|
|||
float scale = (float)inner_rect.height() / (float)m_max;
|
||||
|
||||
Gfx::Point prev_point;
|
||||
for (int i = 0; i < m_values.size(); ++i) {
|
||||
for (size_t i = 0; i < m_values.size(); ++i) {
|
||||
int x = inner_rect.right() - (i * 2) + 1;
|
||||
if (x < 0)
|
||||
break;
|
||||
|
|
|
@ -54,7 +54,9 @@ void TTY::set_default_termios()
|
|||
|
||||
ssize_t TTY::read(FileDescription&, u8* buffer, ssize_t size)
|
||||
{
|
||||
if (m_input_buffer.size() < size)
|
||||
ASSERT(size >= 0);
|
||||
|
||||
if (m_input_buffer.size() < static_cast<size_t>(size))
|
||||
size = m_input_buffer.size();
|
||||
|
||||
if (in_canonical_mode()) {
|
||||
|
|
Loading…
Reference in a new issue