mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 17:10:23 +00:00
AK: Add Vector::remove overload for removing entire ranges
This commit is contained in:
parent
b17a889320
commit
7581b64705
Notes:
sideshowbarker
2024-07-18 23:08:14 +09:00
Author: https://github.com/tomuta Commit: https://github.com/SerenityOS/serenity/commit/7581b64705e Pull-request: https://github.com/SerenityOS/serenity/pull/4467 Reviewed-by: https://github.com/awesomekling Reviewed-by: https://github.com/bgianfo Reviewed-by: https://github.com/bugaevc
1 changed files with 21 additions and 0 deletions
21
AK/Vector.h
21
AK/Vector.h
|
@ -257,6 +257,27 @@ public:
|
|||
--m_size;
|
||||
}
|
||||
|
||||
void remove(size_t index, size_t count)
|
||||
{
|
||||
if (count == 0)
|
||||
return;
|
||||
ASSERT(index + count > index);
|
||||
ASSERT(index + count <= m_size);
|
||||
|
||||
if constexpr (Traits<T>::is_trivial()) {
|
||||
TypedTransfer<T>::copy(slot(index), slot(index + count), m_size - index - count);
|
||||
} else {
|
||||
for (size_t i = index; i < index + count; i++)
|
||||
at(i).~T();
|
||||
for (size_t i = index + count; i < m_size; ++i) {
|
||||
new (slot(i - count)) T(move(at(i)));
|
||||
at(i).~T();
|
||||
}
|
||||
}
|
||||
|
||||
m_size -= count;
|
||||
}
|
||||
|
||||
void insert(size_t index, T&& value)
|
||||
{
|
||||
ASSERT(index <= size());
|
||||
|
|
Loading…
Reference in a new issue