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:
@@ -21,7 +21,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
{
|
||||
readonly Target target;
|
||||
readonly AttackPlane attackPlane;
|
||||
readonly IEnumerable<AmmoPool> ammoPools;
|
||||
readonly AmmoPool[] ammoPools;
|
||||
Activity inner;
|
||||
int ticksUntilTurn;
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
{
|
||||
this.target = target;
|
||||
attackPlane = self.TraitOrDefault<AttackPlane>();
|
||||
ammoPools = self.TraitsImplementing<AmmoPool>();
|
||||
ammoPools = self.TraitsImplementing<AmmoPool>().ToArray();
|
||||
ticksUntilTurn = attackPlane.AttackPlaneInfo.AttackTurnDelay;
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
|
||||
// Move to the next activity only if all ammo pools are depleted and none reload automatically
|
||||
// TODO: This should check whether there is ammo left that is actually suitable for the target
|
||||
if (ammoPools != null && ammoPools.All(x => !x.Info.SelfReloads && !x.HasAmmo()))
|
||||
if (ammoPools.All(x => !x.Info.SelfReloads && !x.HasAmmo()))
|
||||
return NextActivity;
|
||||
|
||||
if (attackPlane != null)
|
||||
|
||||
Reference in New Issue
Block a user