From d62346c0b1e3d55a27c1a35f9606154ca19d422f Mon Sep 17 00:00:00 2001 From: Sergey Bugaev Date: Sat, 21 Nov 2020 21:45:36 +0300 Subject: [PATCH] AK: Add Vector::prepend() overload for multiple items Much like with Vector::append(), you may want to append multiple items in one go. It's actually more important to do this for prepending, because you don't want to copy the rest of items further each time. --- AK/Vector.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/AK/Vector.h b/AK/Vector.h index b58775922c..0fb57faa9d 100644 --- a/AK/Vector.h +++ b/AK/Vector.h @@ -447,6 +447,16 @@ public: m_size += other_size; } + void prepend(const T* values, size_t count) + { + if (!count) + return; + grow_capacity(size() + count); + TypedTransfer::move(slot(count), slot(0), m_size); + TypedTransfer::copy(slot(0), values, count); + m_size += count; + } + void append(const T* values, size_t count) { if (!count)