1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 13:47:45 +00:00

Kernel: Move KBufferBuilder to the fallible KBuffer API

KBufferBuilder::build() now returns an OwnPtr<KBuffer> and can fail.
Clients of the API have been updated to handle that situation.
This commit is contained in:
Andreas Kling 2020-12-18 14:10:10 +01:00
parent d936d86332
commit 8e79bde2b7
18 changed files with 121 additions and 100 deletions

View file

@ -37,6 +37,7 @@ public:
using OutputType = KBuffer;
explicit KBufferBuilder();
KBufferBuilder(KBufferBuilder&&) = default;
~KBufferBuilder() { }
void append(const StringView&);
@ -55,13 +56,18 @@ public:
append(String::formatted(fmtstr, parameters...));
}
KBuffer build();
OwnPtr<KBuffer> build();
private:
bool can_append(size_t) const;
u8* insertion_ptr() { return m_buffer.data() + m_size; }
u8* insertion_ptr()
{
if (!m_buffer)
return nullptr;
return m_buffer->data() + m_size;
}
KBuffer m_buffer;
OwnPtr<KBuffer> m_buffer;
size_t m_size { 0 };
};