make Array::Append faster for simple structs

This makes appending arrays of simple types faster
This commit is contained in:
Ricardo Luís Vaz Silva 2023-04-01 22:32:30 -03:00 committed by Christoph Oelckers
parent 65ea4f91b6
commit fa8df5a4e5

View file

@ -399,10 +399,17 @@ public:
Grow(item.Size());
Count += item.Size();
if constexpr (std::is_trivially_copyable<T>::value)
{
memcpy(Array + start,item.Array,item.Size() * sizeof(T));
}
else
{
for (unsigned i = 0; i < item.Size(); i++)
{
new(&Array[start + i]) T(item[i]);
}
}
return start;
}
@ -413,10 +420,17 @@ public:
Grow(item.Size());
Count += item.Size();
if constexpr (std::is_trivially_copyable<T>::value)
{
memcpy(Array + start,item.Array,item.Size() * sizeof(T));
}
else
{
for (unsigned i = 0; i < item.Size(); i++)
{
new(&Array[start + i]) T(std::move(item[i]));
}
}
item.Clear();
return start;
}