diff --git a/Source/Engine/Core/Collections/Array.h b/Source/Engine/Core/Collections/Array.h
index 40a458ece..7281fa8d8 100644
--- a/Source/Engine/Core/Collections/Array.h
+++ b/Source/Engine/Core/Collections/Array.h
@@ -579,7 +579,7 @@ public:
/// Insert the given item at specified index with keeping items order.
///
/// The zero-based index at which item should be inserted.
- /// The item to insert.
+ /// The item to be inserted by copying.
void Insert(int32 index, const T& item)
{
ASSERT(index >= 0 && index <= _count);
@@ -592,6 +592,23 @@ public:
data[index] = item;
}
+ ///
+ /// Insert the given item at specified index with keeping items order.
+ ///
+ /// The zero-based index at which item should be inserted.
+ /// The item to inserted by moving.
+ void Insert(int32 index, T&& item)
+ {
+ ASSERT(index >= 0 && index <= _count);
+ EnsureCapacity(_count + 1);
+ T* data = _allocation.Get();
+ Memory::ConstructItems(data + _count, 1);
+ for (int32 i = _count - 1; i >= index; i--)
+ data[i + 1] = MoveTemp(data[i]);
+ _count++;
+ data[index] = MoveTemp(item);
+ }
+
///
/// Insert the given item at specified index with keeping items order.
///
@@ -772,9 +789,9 @@ public:
///
/// Performs pop from stack operation (stack grows at the end of the collection).
///
- T Pop()
+ FORCE_INLINE T Pop()
{
- T item(Last());
+ T item = MoveTemp(Last());
RemoveLast();
return item;
}
@@ -807,6 +824,15 @@ public:
Add(item);
}
+ ///
+ /// Performs enqueue to queue operation (queue head is in the beginning of queue).
+ ///
+ /// The item to append.
+ void Enqueue(T&& item)
+ {
+ Add(MoveTemp(item));
+ }
+
///
/// Performs dequeue from queue operation (queue head is in the beginning of queue).
///
@@ -814,7 +840,7 @@ public:
T Dequeue()
{
ASSERT(HasItems());
- T item(First());
+ T item = MoveTemp(_allocation.Get()[0]);
RemoveAtKeepOrder(0);
return item;
}