mirror of
https://github.com/SerenityOS/serenity.git
synced 2026-11-07 04:29:30 -10:00
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:
1 parent
adede105a1
commit
147b06ad2f
1 file changed
+7
@@ -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(); }
|
||||
|
||||
|
||||
Reference in new issue
Block a user