Refactor and improve collections code

#3043
This commit is contained in:
Wojtek Figat
2025-01-23 14:44:11 +01:00
parent af416fe0c8
commit f5280eab74
13 changed files with 277 additions and 268 deletions

View File

@@ -0,0 +1,24 @@
// Copyright (c) 2012-2024 Wojciech Figat. All rights reserved.
#pragma once
#include "Allocation.h"
#include "Engine/Core/Templates.h"
namespace AllocationUtils
{
// Moves the data from the source allocation to the destination allocation.
template<typename T, typename AllocationType>
inline void MoveToEmpty(typename AllocationType::template Data<T>& to, typename AllocationType::template Data<T>& from, const int32 fromCount, const int32 fromCapacity)
{
if IF_CONSTEXPR (AllocationType::HasSwap)
to.Swap(from);
else
{
to.Allocate(fromCapacity);
Memory::MoveItems(to.Get(), from.Get(), fromCount);
Memory::DestructItems(from.Get(), fromCount);
from.Free();
}
}
}