[*] InternalHeap::_ZRealloc and _FRealloc parity

This commit is contained in:
Reece Wilson 2024-12-01 09:02:20 +00:00
parent 7d77e625ea
commit 39cf09560f

View File

@ -200,16 +200,40 @@ namespace Aurora::Memory
void *InternalHeap::_ZRealloc(void *pBuffer, Types::size_t uLength)
{
auto prevLength = GetHeapSize(pBuffer);
auto alloc = this->_ZAlloc(uLength);
if (!alloc)
if (pBuffer)
{
if (!uLength)
{
this->_Free(pBuffer);
return nullptr;
}
AuMemcpy(alloc, pBuffer, AuMin(prevLength, uLength));
auto uLengthOld = this->GetChunkSize(pBuffer);
if (uLengthOld >= uLength)
{
return pBuffer;
}
if (auto pNext = this->_ZAlloc(uLength))
{
AuMemcpy(pNext, pBuffer, AuMin(uLengthOld, uLength));
this->_Free(pBuffer);
return alloc;
return pNext;
}
else
{
return nullptr;
}
}
else if (uLength)
{
return this->_ZAlloc(uLength);
}
else
{
return nullptr;
}
}
void *InternalHeap::_ZRealloc(void *pBuffer, Types::size_t uLength, Types::size_t uAlign)
@ -220,16 +244,40 @@ namespace Aurora::Memory
void *InternalHeap::_FRealloc(void *pBuffer, Types::size_t uLength)
{
auto prevLength = GetHeapSize(pBuffer);
auto alloc = this->_FAlloc(uLength);
if (!alloc)
if (pBuffer)
{
if (!uLength)
{
this->_Free(pBuffer);
return nullptr;
}
AuMemcpy(alloc, pBuffer, AuMin(prevLength, uLength));
auto uLengthOld = this->GetChunkSize(pBuffer);
if (uLengthOld >= uLength)
{
return pBuffer;
}
if (auto pNext = this->_FAlloc(uLength))
{
AuMemcpy(pNext, pBuffer, AuMin(uLengthOld, uLength));
this->_Free(pBuffer);
return alloc;
return pNext;
}
else
{
return nullptr;
}
}
else if (uLength)
{
return this->_FAlloc(uLength);
}
else
{
return nullptr;
}
}
void *InternalHeap::_FRealloc(void *pBuffer, Types::size_t uLength, Types::size_t uAlign)