瀏覽代碼

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.
Sergey Bugaev 4 年之前
父節點
當前提交
d62346c0b1
共有 1 個文件被更改,包括 10 次插入0 次删除
  1. 10 0
      AK/Vector.h

+ 10 - 0
AK/Vector.h

@@ -447,6 +447,16 @@ public:
         m_size += other_size;
         m_size += other_size;
     }
     }
 
 
+    void prepend(const T* values, size_t count)
+    {
+        if (!count)
+            return;
+        grow_capacity(size() + count);
+        TypedTransfer<T>::move(slot(count), slot(0), m_size);
+        TypedTransfer<T>::copy(slot(0), values, count);
+        m_size += count;
+    }
+
     void append(const T* values, size_t count)
     void append(const T* values, size_t count)
     {
     {
         if (!count)
         if (!count)