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,9 +399,16 @@ public:
Grow(item.Size()); Grow(item.Size());
Count += item.Size(); Count += item.Size();
for (unsigned i = 0; i < item.Size(); i++) if constexpr (std::is_trivially_copyable<T>::value)
{ {
new(&Array[start + i]) T(item[i]); 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; return start;
} }
@ -413,9 +420,16 @@ public:
Grow(item.Size()); Grow(item.Size());
Count += item.Size(); Count += item.Size();
for (unsigned i = 0; i < item.Size(); i++) if constexpr (std::is_trivially_copyable<T>::value)
{ {
new(&Array[start + i]) T(std::move(item[i])); 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(); item.Clear();
return start; return start;