mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-11 05:25:32 +03:00
AK: Use TypedTransfer to move vector's inline buffer
This avoids an explicit loop-move when the type is trivial.
This commit is contained in:
parent
6970bf03a9
commit
48a4c9c1ad
Notes:
sideshowbarker
2024-07-17 05:18:58 +09:00
Author: https://github.com/alimpfard Commit: https://github.com/SerenityOS/serenity/commit/48a4c9c1ad Pull-request: https://github.com/SerenityOS/serenity/pull/15994
@ -31,7 +31,7 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t copy(T* destination, const T* source, size_t count)
|
static size_t copy(T* destination, T const* source, size_t count)
|
||||||
{
|
{
|
||||||
if (count == 0)
|
if (count == 0)
|
||||||
return 0;
|
return 0;
|
||||||
@ -54,7 +54,7 @@ public:
|
|||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool compare(const T* a, const T* b, size_t count)
|
static bool compare(T const* a, T const* b, size_t count)
|
||||||
{
|
{
|
||||||
if (count == 0)
|
if (count == 0)
|
||||||
return true;
|
return true;
|
||||||
@ -69,6 +69,19 @@ public:
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void delete_(T* ptr, size_t count)
|
||||||
|
{
|
||||||
|
if (count == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if constexpr (Traits<T>::is_trivial()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (size_t i = 0; i < count; ++i)
|
||||||
|
ptr[i].~T();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -73,10 +73,8 @@ public:
|
|||||||
{
|
{
|
||||||
if constexpr (inline_capacity > 0) {
|
if constexpr (inline_capacity > 0) {
|
||||||
if (!m_outline_buffer) {
|
if (!m_outline_buffer) {
|
||||||
for (size_t i = 0; i < m_size; ++i) {
|
TypedTransfer<T>::move(inline_buffer(), other.inline_buffer(), m_size);
|
||||||
new (&inline_buffer()[i]) StorageType(move(other.inline_buffer()[i]));
|
TypedTransfer<T>::delete_(other.inline_buffer(), m_size);
|
||||||
other.inline_buffer()[i].~StorageType();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
other.m_outline_buffer = nullptr;
|
other.m_outline_buffer = nullptr;
|
||||||
|
Loading…
Reference in New Issue
Block a user