1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 10:48:11 +00:00

KBuffer: Add set_size() and LogStream operator<<

It will be useful to be able to set the "public" size of a KBuffer.
It can still have a different amount of memory allocated internally.
This commit is contained in:
Andreas Kling 2019-08-06 07:31:52 +02:00
parent da6c8fe3f8
commit f58b0c245d

View file

@ -11,6 +11,7 @@
// severely limited kmalloc heap.
#include <AK/Assertions.h>
#include <AK/LogStream.h>
#include <Kernel/VM/MemoryManager.h>
#include <Kernel/VM/Region.h>
@ -35,6 +36,12 @@ public:
size_t size() const { return m_size; }
size_t capacity() const { return m_region->size(); }
void set_size(size_t size)
{
ASSERT(size <= capacity());
m_size = size;
}
private:
explicit KBufferImpl(NonnullRefPtr<Region>&& region, size_t size)
: m_size(size)
@ -63,6 +70,8 @@ public:
size_t size() const { return m_impl->size(); }
size_t capacity() const { return m_impl->size(); }
void set_size(size_t size) { m_impl->set_size(size); }
const KBufferImpl& impl() const { return m_impl; }
KBuffer(const ByteBuffer& buffer)
@ -78,3 +87,8 @@ private:
NonnullRefPtr<KBufferImpl> m_impl;
};
inline const LogStream& operator<<(const LogStream& stream, const KBuffer& value)
{
return stream << StringView(value.data(), value.size());
}