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

Vector: Use memcpy when dynamically growing Vectors of trivial types

This commit is contained in:
Andreas Kling 2019-08-07 15:35:23 +02:00
parent 6da6ca64d2
commit 5487f81b5d

View file

@ -436,9 +436,14 @@ public:
return; return;
int new_capacity = needed_capacity; int new_capacity = needed_capacity;
auto* new_buffer = (T*)kmalloc(new_capacity * sizeof(T)); auto* new_buffer = (T*)kmalloc(new_capacity * sizeof(T));
for (int i = 0; i < m_size; ++i) {
new (&new_buffer[i]) T(move(at(i))); if constexpr (Traits<T>::is_trivial()) {
at(i).~T(); TypedTransfer<T>::copy(new_buffer, data(), m_size);
} else {
for (int i = 0; i < m_size; ++i) {
new (&new_buffer[i]) T(move(at(i)));
at(i).~T();
}
} }
if (m_outline_buffer) if (m_outline_buffer)
kfree(m_outline_buffer); kfree(m_outline_buffer);