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:
parent
6228e18a09
commit
2c7b0b8893
2 changed files with 54 additions and 4 deletions
13
AK/Vector.h
13
AK/Vector.h
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue