mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 05:47:35 +00:00
Vector: Use memcpy when dynamically growing Vectors of trivial types
This commit is contained in:
parent
6da6ca64d2
commit
5487f81b5d
1 changed files with 8 additions and 3 deletions
|
@ -436,10 +436,15 @@ public:
|
|||
return;
|
||||
int new_capacity = needed_capacity;
|
||||
auto* new_buffer = (T*)kmalloc(new_capacity * sizeof(T));
|
||||
|
||||
if constexpr (Traits<T>::is_trivial()) {
|
||||
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)
|
||||
kfree(m_outline_buffer);
|
||||
m_outline_buffer = new_buffer;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue