1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-26 00:04:43 +01:00

Refactor to avoid unnecessary copies (#13736)

* Refactor to avoid unnecessary copies

* Fix dangling references
This commit is contained in:
skdltmxn
2021-01-12 06:14:15 +09:00
committed by GitHub
parent b58038a23f
commit 7ef4d7762f
23 changed files with 52 additions and 40 deletions

View File

@@ -52,8 +52,16 @@ namespace OpenRCT2
}
MemoryStream::MemoryStream(MemoryStream&& mv) noexcept
: _access(mv._access)
, _dataCapacity(mv._dataCapacity)
, _dataSize(mv._dataSize)
, _data(mv._data)
, _position(mv._position)
{
*this = std::move(mv);
mv._data = nullptr;
mv._position = nullptr;
mv._dataCapacity = 0;
mv._dataSize = 0;
}
MemoryStream::~MemoryStream()
@@ -69,15 +77,19 @@ namespace OpenRCT2
MemoryStream& MemoryStream::operator=(MemoryStream&& mv) noexcept
{
_access = mv._access;
_dataCapacity = mv._dataCapacity;
_data = mv._data;
_position = mv._position;
if (this != &mv)
{
_access = mv._access;
_dataCapacity = mv._dataCapacity;
_data = mv._data;
_dataSize = mv._dataSize;
_position = mv._position;
mv._data = nullptr;
mv._position = nullptr;
mv._dataCapacity = 0;
mv._dataSize = 0;
mv._data = nullptr;
mv._position = nullptr;
mv._dataCapacity = 0;
mv._dataSize = 0;
}
return *this;
}