AK: Add ByteBuffer::clone

This adds a function to clone a ByteBuffer with a way to propagate
errors if they occur.
This commit is contained in:
Undefine authored and Lucas Chollet committed 2026-11-06 20:34:06 +01:00
1 parent adede105a1
commit 147b06ad2f
1 file changed
+7
+7
View File
@@ -300,6 +300,13 @@ public:
__builtin_memset(data(), 0, m_size);
}
ErrorOr<ByteBuffer> clone() const
{
auto clone = TRY(ByteBuffer::create_uninitialized(size()));
__builtin_memcpy(clone.data(), data(), size());
return clone;
}
operator Bytes() { return bytes(); }
operator ReadonlyBytes() const { return bytes(); }