Skip to content

Commit 972e723

Browse files
committed
mutator refactor:
-append to a list instead of creating a new list for every object -store mutators as an array since it won't need to be reallocated once created
1 parent 8ed5785 commit 972e723

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

Source/ModifyObject.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace Mutiny
99
{
1010
internal class ModifyObject : ScenePatch
1111
{
12-
Dictionary<string, List<Action<object>>> m_gameObjectMutators = new Dictionary<string, List<Action<object>>>();
12+
Dictionary<string, Action<object>[]> m_gameObjectMutators = new Dictionary<string, Action<object>[]>();
1313

1414
public override void Load(ConfigNode configNode)
1515
{
@@ -21,6 +21,8 @@ public override void Load(ConfigNode configNode)
2121
}
2222
}
2323

24+
#region Reflection
25+
2426
private static MemberInfo GetMemberInfo(Type objectType, string memberName)
2527
{
2628
MemberInfo memberInfo = objectType.GetField(memberName);
@@ -58,10 +60,9 @@ private static Action<object> CreateMutator(ConfigNode.Value configValue, Type o
5860
return null;
5961
}
6062

61-
private static List<Action<object>> CreateMutators(ConfigNode configNode, Type objectType)
62-
{
63-
List<Action<object>> mutators = new List<Action<object>>();
6463

64+
private static void CreateMutators(ConfigNode configNode, Type objectType, List<Action<object>> mutators)
65+
{
6566
foreach (ConfigNode.Value configValue in configNode.values.values)
6667
{
6768
var mutator = CreateMutator(configValue, objectType);
@@ -70,10 +71,17 @@ private static List<Action<object>> CreateMutators(ConfigNode configNode, Type o
7071
mutators.Add(mutator);
7172
}
7273
}
74+
}
7375

74-
return mutators;
76+
private static Action<object>[] CreateMutators(ConfigNode configNode, Type objectType)
77+
{
78+
List<Action<object>> mutators = new List<Action<object>>();
79+
CreateMutators(configNode, objectType, mutators);
80+
return mutators.ToArray();
7581
}
7682

83+
#endregion
84+
7785
public override void Execute()
7886
{
7987
foreach (var objectMutator in m_gameObjectMutators)

0 commit comments

Comments
 (0)