mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-29 16:21:29 +00: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
11
AK/Vector.h
11
AK/Vector.h
|
@ -436,9 +436,14 @@ public:
|
|||
return;
|
||||
int new_capacity = needed_capacity;
|
||||
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)));
|
||||
at(i).~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);
|
||||
|
|
Loading…
Reference in a new issue