mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-11 05:25:32 +03:00
Vector: Use memcpy when dynamically growing Vectors of trivial types
This commit is contained in:
parent
6da6ca64d2
commit
5487f81b5d
Notes:
sideshowbarker
2024-07-19 12:50:35 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/5487f81b5de
@ -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…
Reference in New Issue
Block a user