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:
RoosterDragon
2015-04-20 23:48:00 +01:00
parent 2937a31463
commit fb0cab7481
18 changed files with 45 additions and 47 deletions

View File

@@ -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)