mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-31 02:35:46 +01:00
Remove Memory::Duplicate and Memory::DuplicateArray (#7142)
This commit is contained in:
@@ -88,20 +88,6 @@ namespace Memory
|
||||
free((void*)ptr);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static T * Duplicate(const T * src, size_t size)
|
||||
{
|
||||
T *result = Allocate<T>(size);
|
||||
return (T *)memcpy(result, src, size);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static T * DuplicateArray(const T * src, size_t count)
|
||||
{
|
||||
T * result = AllocateArray<T>(count);
|
||||
return (T *)memcpy(result, src, count * sizeof(T));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static void FreeArray(T * ptr, size_t count)
|
||||
{
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#pragma endregion
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include "Math.hpp"
|
||||
#include "Memory.hpp"
|
||||
#include "MemoryStream.h"
|
||||
@@ -27,7 +28,8 @@ MemoryStream::MemoryStream(const MemoryStream ©)
|
||||
|
||||
if (_access & MEMORY_ACCESS::OWNER)
|
||||
{
|
||||
_data = Memory::Duplicate(copy._data, _dataCapacity);
|
||||
_data = Memory::Allocate<void>(_dataCapacity);
|
||||
std::memcpy(_data, copy._data, _dataCapacity);
|
||||
_position = (void*)((uintptr_t)_data + copy.GetPosition());
|
||||
}
|
||||
}
|
||||
@@ -71,7 +73,9 @@ const void * MemoryStream::GetData() const
|
||||
|
||||
void * MemoryStream::GetDataCopy() const
|
||||
{
|
||||
return Memory::Duplicate(_data, _dataSize);
|
||||
auto result = Memory::Allocate<void>(_dataSize);
|
||||
std::memcpy(result, _data, _dataSize);
|
||||
return result;
|
||||
}
|
||||
|
||||
void * MemoryStream::TakeData()
|
||||
|
||||
@@ -324,8 +324,9 @@ namespace String
|
||||
utf8 * result = nullptr;
|
||||
if (src != nullptr)
|
||||
{
|
||||
size_t srcSize = SizeOf(src);
|
||||
result = Memory::DuplicateArray(src, srcSize + 1);
|
||||
size_t srcSize = SizeOf(src) + 1;
|
||||
result = Memory::Allocate<utf8>(srcSize);
|
||||
memcpy(result, src, srcSize);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user