Cache results of TraitsImplementing calls.
If a class is caching the TraitsImplementing enumerable, instead cache the results of enumerating it to an array. The avoids having to enumerate the sequence each time it is needed.
This commit is contained in:
@@ -25,7 +25,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
static readonly List<CPos> NoPath = new List<CPos>();
|
||||
|
||||
readonly Mobile mobile;
|
||||
readonly IEnumerable<IDisableMove> moveDisablers;
|
||||
readonly IDisableMove[] moveDisablers;
|
||||
readonly WRange nearEnough;
|
||||
readonly Func<List<CPos>> getPath;
|
||||
readonly Actor ignoredActor;
|
||||
@@ -43,7 +43,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
public Move(Actor self, CPos destination)
|
||||
{
|
||||
mobile = self.Trait<Mobile>();
|
||||
moveDisablers = self.TraitsImplementing<IDisableMove>();
|
||||
moveDisablers = self.TraitsImplementing<IDisableMove>().ToArray();
|
||||
|
||||
getPath = () =>
|
||||
self.World.WorldActor.Trait<IPathFinder>().FindPath(
|
||||
@@ -60,7 +60,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
public Move(Actor self, CPos destination, WRange nearEnough)
|
||||
{
|
||||
mobile = self.Trait<Mobile>();
|
||||
moveDisablers = self.TraitsImplementing<IDisableMove>();
|
||||
moveDisablers = self.TraitsImplementing<IDisableMove>().ToArray();
|
||||
|
||||
getPath = () => self.World.WorldActor.Trait<IPathFinder>()
|
||||
.FindUnitPath(mobile.ToCell, destination, self);
|
||||
@@ -71,7 +71,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
public Move(Actor self, CPos destination, SubCell subCell, WRange nearEnough)
|
||||
{
|
||||
mobile = self.Trait<Mobile>();
|
||||
moveDisablers = self.TraitsImplementing<IDisableMove>();
|
||||
moveDisablers = self.TraitsImplementing<IDisableMove>().ToArray();
|
||||
|
||||
getPath = () => self.World.WorldActor.Trait<IPathFinder>()
|
||||
.FindUnitPathToRange(mobile.FromCell, subCell, self.World.Map.CenterOfSubCell(destination, subCell), nearEnough, self);
|
||||
@@ -82,7 +82,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
public Move(Actor self, CPos destination, Actor ignoredActor)
|
||||
{
|
||||
mobile = self.Trait<Mobile>();
|
||||
moveDisablers = self.TraitsImplementing<IDisableMove>();
|
||||
moveDisablers = self.TraitsImplementing<IDisableMove>().ToArray();
|
||||
|
||||
getPath = () =>
|
||||
self.World.WorldActor.Trait<IPathFinder>().FindPath(
|
||||
@@ -97,7 +97,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
public Move(Actor self, Target target, WRange range)
|
||||
{
|
||||
mobile = self.Trait<Mobile>();
|
||||
moveDisablers = self.TraitsImplementing<IDisableMove>();
|
||||
moveDisablers = self.TraitsImplementing<IDisableMove>().ToArray();
|
||||
|
||||
getPath = () =>
|
||||
{
|
||||
@@ -115,7 +115,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
public Move(Actor self, Func<List<CPos>> getPath)
|
||||
{
|
||||
mobile = self.Trait<Mobile>();
|
||||
moveDisablers = self.TraitsImplementing<IDisableMove>();
|
||||
moveDisablers = self.TraitsImplementing<IDisableMove>().ToArray();
|
||||
|
||||
this.getPath = getPath;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user