Merge branch 'mtszkarbowiak-fix/move-semantics'

This commit is contained in:
Wojtek Figat
2024-07-25 10:53:50 +02:00
3 changed files with 46 additions and 5 deletions

View File

@@ -579,7 +579,7 @@ public:
/// Insert the given item at specified index with keeping items order. /// Insert the given item at specified index with keeping items order.
/// </summary> /// </summary>
/// <param name="index">The zero-based index at which item should be inserted.</param> /// <param name="index">The zero-based index at which item should be inserted.</param>
/// <param name="item">The item to insert.</param> /// <param name="item">The item to be inserted by copying.</param>
void Insert(int32 index, const T& item) void Insert(int32 index, const T& item)
{ {
ASSERT(index >= 0 && index <= _count); ASSERT(index >= 0 && index <= _count);
@@ -592,6 +592,23 @@ public:
data[index] = item; data[index] = item;
} }
/// <summary>
/// Insert the given item at specified index with keeping items order.
/// </summary>
/// <param name="index">The zero-based index at which item should be inserted.</param>
/// <param name="item">The item to inserted by moving.</param>
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);
}
/// <summary> /// <summary>
/// Insert the given item at specified index with keeping items order. /// Insert the given item at specified index with keeping items order.
/// </summary> /// </summary>
@@ -772,9 +789,9 @@ public:
/// <summary> /// <summary>
/// Performs pop from stack operation (stack grows at the end of the collection). /// Performs pop from stack operation (stack grows at the end of the collection).
/// </summary> /// </summary>
T Pop() FORCE_INLINE T Pop()
{ {
T item(Last()); T item = MoveTemp(Last());
RemoveLast(); RemoveLast();
return item; return item;
} }
@@ -807,6 +824,15 @@ public:
Add(item); Add(item);
} }
/// <summary>
/// Performs enqueue to queue operation (queue head is in the beginning of queue).
/// </summary>
/// <param name="item">The item to append.</param>
void Enqueue(T&& item)
{
Add(MoveTemp(item));
}
/// <summary> /// <summary>
/// Performs dequeue from queue operation (queue head is in the beginning of queue). /// Performs dequeue from queue operation (queue head is in the beginning of queue).
/// </summary> /// </summary>
@@ -814,7 +840,7 @@ public:
T Dequeue() T Dequeue()
{ {
ASSERT(HasItems()); ASSERT(HasItems());
T item(First()); T item = MoveTemp(_allocation.Get()[0]);
RemoveAtKeepOrder(0); RemoveAtKeepOrder(0);
return item; return item;
} }

View File

@@ -543,6 +543,15 @@ void Actor::SetLayerRecursive(int32 layerIndex)
OnLayerChanged(); OnLayerChanged();
} }
void Actor::SetName(String&& value)
{
if (_name == value)
return;
_name = MoveTemp(value);
if (GetScene())
Level::callActorEvent(Level::ActorEventType::OnActorNameChanged, this, nullptr);
}
void Actor::SetName(const StringView& value) void Actor::SetName(const StringView& value)
{ {
if (_name == value) if (_name == value)

View File

@@ -185,7 +185,13 @@ public:
/// Sets the actor name. /// Sets the actor name.
/// </summary> /// </summary>
/// <param name="value">The value to set.</param> /// <param name="value">The value to set.</param>
API_PROPERTY() void SetName(const StringView& value); API_PROPERTY() void SetName(String&& value);
/// <summary>
/// Sets the actor name.
/// </summary>
/// <param name="value">The value to set.</param>
void SetName(const StringView& value);
public: public:
/// <summary> /// <summary>