aboutsummaryrefslogtreecommitdiff
path: root/zencore/sharedbuffer.cpp
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2021-09-01 11:35:53 +0200
committerStefan Boberg <[email protected]>2021-09-01 11:35:53 +0200
commit551636500b210a302f1a868b889eb82b5c87c2ac (patch)
treee62884ff8a1af88ca8c446e24e3a72735c9e76ca /zencore/sharedbuffer.cpp
parentCompactBinary: Added explicit operator bool for array and object types (diff)
downloadzen-551636500b210a302f1a868b889eb82b5c87c2ac.tar.xz
zen-551636500b210a302f1a868b889eb82b5c87c2ac.zip
SharedBuffer: MakeOwned now returns a buffer instead of operating in-place
CL15713705
Diffstat (limited to 'zencore/sharedbuffer.cpp')
-rw-r--r--zencore/sharedbuffer.cpp30
1 files changed, 18 insertions, 12 deletions
diff --git a/zencore/sharedbuffer.cpp b/zencore/sharedbuffer.cpp
index 9c788d29f..a14da1bf7 100644
--- a/zencore/sharedbuffer.cpp
+++ b/zencore/sharedbuffer.cpp
@@ -53,24 +53,30 @@ SharedBuffer::SharedBuffer(UniqueBuffer&& InBuffer) : m_Buffer(std::move(InBuffe
{
}
-SharedBuffer&
-SharedBuffer::MakeOwned()
+SharedBuffer
+SharedBuffer::MakeOwned() const&
{
if (IsOwned() || !m_Buffer)
{
return *this;
}
+ else
+ {
+ return Clone(GetView());
+ }
+}
- const uint64_t Size = m_Buffer->DataBytes();
- void* Buffer = Memory::Alloc(Size, 16);
- IoBufferCore* NewOwner = new IoBufferCore(Buffer, Size);
- NewOwner->SetIsOwnedByThis(true);
-
- memcpy(Buffer, m_Buffer->DataPointer(), Size);
-
- m_Buffer = NewOwner;
-
- return *this;
+SharedBuffer
+SharedBuffer::MakeOwned() &&
+{
+ if (IsOwned())
+ {
+ return std::move(*this);
+ }
+ else
+ {
+ return Clone(GetView());
+ }
}
SharedBuffer