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

@@ -84,13 +84,13 @@ namespace OpenRA.Mods.Common.Scripting
[ScriptPropertyGroup("Production")]
public class ProductionQueueProperties : ScriptActorProperties, Requires<ProductionQueueInfo>, Requires<ScriptTriggersInfo>
{
readonly List<ProductionQueue> queues;
readonly ProductionQueue[] queues;
readonly ScriptTriggers triggers;
public ProductionQueueProperties(ScriptContext context, Actor self)
: base(context, self)
{
queues = self.TraitsImplementing<ProductionQueue>().Where(q => q.Enabled).ToList();
queues = self.TraitsImplementing<ProductionQueue>().Where(q => q.Enabled).ToArray();
triggers = TriggerGlobal.GetScriptTriggers(self);
}