mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-22 12:11:25 +00:00
make Array::Append faster for simple structs
This makes appending arrays of simple types faster
This commit is contained in:
parent
65ea4f91b6
commit
fa8df5a4e5
1 changed files with 18 additions and 4 deletions
|
@ -399,9 +399,16 @@ public:
|
|||
Grow(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;
|
||||
}
|
||||
|
@ -413,9 +420,16 @@ public:
|
|||
Grow(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();
|
||||
return start;
|
||||
|
|
Loading…
Reference in a new issue