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

@@ -19,7 +19,7 @@ namespace OpenRA.Mods.Common.Activities
class Demolish : Enter
{
readonly Actor target;
readonly IEnumerable<IDemolishable> demolishables;
readonly IDemolishable[] demolishables;
readonly int delay;
readonly int flashes;
readonly int flashesDelay;
@@ -32,7 +32,7 @@ namespace OpenRA.Mods.Common.Activities
: base(self, target)
{
this.target = target;
demolishables = target.TraitsImplementing<IDemolishable>();
demolishables = target.TraitsImplementing<IDemolishable>().ToArray();
this.delay = delay;
this.flashes = flashes;
this.flashesDelay = flashesDelay;