1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 03:57:44 +00:00

Vector: Use memcpy to implement remove() for trivial types

This is a lot faster than the generic code path.
Also added some unit testing for this.
This commit is contained in:
Andreas Kling 2019-08-12 10:35:05 +02:00
parent 6228e18a09
commit 2c7b0b8893
2 changed files with 54 additions and 4 deletions

View file

@ -266,10 +266,15 @@ public:
void remove(int index)
{
ASSERT(index < m_size);
at(index).~T();
for (int i = index + 1; i < m_size; ++i) {
new (slot(i - 1)) T(move(at(i)));
at(i).~T();
if constexpr (Traits<T>::is_trivial()) {
TypedTransfer<T>::copy(slot(index), slot(index + 1), m_size - index - 1);
} else {
at(index).~T();
for (int i = index + 1; i < m_size; ++i) {
new (slot(i - 1)) T(move(at(i)));
at(i).~T();
}
}
--m_size;