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.
/// </summary>
/// <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)
{
ASSERT(index >= 0 && index <= _count);
@@ -592,6 +592,23 @@ public:
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>
/// Insert the given item at specified index with keeping items order.
/// </summary>
@@ -772,9 +789,9 @@ public:
/// <summary>
/// Performs pop from stack operation (stack grows at the end of the collection).
/// </summary>
T Pop()
FORCE_INLINE T Pop()
{
T item(Last());
T item = MoveTemp(Last());
RemoveLast();
return item;
}
@@ -807,6 +824,15 @@ public:
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>
/// Performs dequeue from queue operation (queue head is in the beginning of queue).
/// </summary>
@@ -814,7 +840,7 @@ public:
T Dequeue()
{
ASSERT(HasItems());
T item(First());
T item = MoveTemp(_allocation.Get()[0]);
RemoveAtKeepOrder(0);
return item;
}

View File

@@ -543,6 +543,15 @@ void Actor::SetLayerRecursive(int32 layerIndex)
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)
{
if (_name == value)

View File

@@ -185,7 +185,13 @@ public:
/// Sets the actor name.
/// </summary>
/// <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:
/// <summary>