1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 20:27:34 +00:00

AK: Turn ByteBuffer into a value type

Previously ByteBuffer would internally hold a RefPtr to the byte
buffer and would behave like a reference type, i.e. copying a
ByteBuffer would not create a duplicate byte buffer, but rather
two objects which refer to the same internal buffer.

This also changes ByteBuffer so that it has some internal capacity
much like the Vector<T> type. Unlike Vector<T> however a byte
buffer's data may be uninitialized.

With this commit ByteBuffer makes use of the kmalloc_good_size()
API to pick an optimal allocation size for its internal buffer.
This commit is contained in:
Gunnar Beutner 2021-05-14 20:53:04 +02:00 committed by Andreas Kling
parent f0fa51773a
commit fcaf98361f
9 changed files with 176 additions and 236 deletions

View file

@ -62,13 +62,11 @@ public:
private:
void will_append(size_t);
u8* data() { return m_buffer.is_null() ? m_inline_buffer : m_buffer.data(); }
const u8* data() const { return m_buffer.is_null() ? m_inline_buffer : m_buffer.data(); }
bool using_inline_buffer() const { return m_buffer.is_null(); }
u8* data() { return m_buffer.data(); }
const u8* data() const { return m_buffer.data(); }
static constexpr size_t inline_capacity = 128;
u8 m_inline_buffer[inline_capacity];
ByteBuffer m_buffer;
AK::Detail::ByteBuffer<inline_capacity> m_buffer;
size_t m_length { 0 };
};