From 02403377cd52b8407733b149bf898e78d6d0b591 Mon Sep 17 00:00:00 2001
From: Mateusz Karbowiak <69864511+mtszkarbowiak@users.noreply.github.com>
Date: Sat, 22 Jun 2024 15:13:53 +0200
Subject: [PATCH 1/3] Array move semantics fix
---
Source/Engine/Core/Collections/Array.h | 34 +++++++++++++++++++++++---
1 file changed, 30 insertions(+), 4 deletions(-)
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;
}
From 5f4aee71b8c1de3a99e92b0ce8017fd9f07dcfb5 Mon Sep 17 00:00:00 2001
From: Mateusz Karbowiak <69864511+mtszkarbowiak@users.noreply.github.com>
Date: Sat, 22 Jun 2024 15:14:02 +0200
Subject: [PATCH 2/3] Actor naming without string copy fix
---
Source/Engine/Level/Actor.cpp | 9 +++++++++
Source/Engine/Level/Actor.h | 5 +++++
2 files changed, 14 insertions(+)
diff --git a/Source/Engine/Level/Actor.cpp b/Source/Engine/Level/Actor.cpp
index a30a929de..1cdfccd3b 100644
--- a/Source/Engine/Level/Actor.cpp
+++ b/Source/Engine/Level/Actor.cpp
@@ -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)
diff --git a/Source/Engine/Level/Actor.h b/Source/Engine/Level/Actor.h
index dc77cdbee..fdf587b07 100644
--- a/Source/Engine/Level/Actor.h
+++ b/Source/Engine/Level/Actor.h
@@ -181,6 +181,11 @@ public:
return _name;
}
+ ///
+ /// Sets the actor name without copying the string.
+ ///
+ API_FUNCTION() void SetName(String&& value);
+
///
/// Sets the actor name.
///
From cb3e8e4112c4bbf9ba461d1fa386c6b699fba331 Mon Sep 17 00:00:00 2001
From: Mateusz Karbowiak <69864511+mtszkarbowiak@users.noreply.github.com>
Date: Sat, 22 Jun 2024 16:41:29 +0200
Subject: [PATCH 3/3] Ambiguous name fix
---
Source/Engine/Level/Actor.cpp | 2 +-
Source/Engine/Level/Actor.h | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/Source/Engine/Level/Actor.cpp b/Source/Engine/Level/Actor.cpp
index 1cdfccd3b..08d2832d1 100644
--- a/Source/Engine/Level/Actor.cpp
+++ b/Source/Engine/Level/Actor.cpp
@@ -543,7 +543,7 @@ void Actor::SetLayerRecursive(int32 layerIndex)
OnLayerChanged();
}
-void Actor::SetName(String&& value)
+void Actor::SetNameNoCopy(String&& value)
{
if (_name == value)
return;
diff --git a/Source/Engine/Level/Actor.h b/Source/Engine/Level/Actor.h
index fdf587b07..787cc6835 100644
--- a/Source/Engine/Level/Actor.h
+++ b/Source/Engine/Level/Actor.h
@@ -184,7 +184,7 @@ public:
///
/// Sets the actor name without copying the string.
///
- API_FUNCTION() void SetName(String&& value);
+ void SetNameNoCopy(String&& value);
///
/// Sets the actor name.