From 287ead56b3fefe57524d666dc1507853c13efb26 Mon Sep 17 00:00:00 2001 From: RoosterDragon Date: Mon, 30 Mar 2015 21:05:10 +0100 Subject: [PATCH] Avoid allocating a delegate and new list in every tick of RepairableBuilding. --- OpenRA.Mods.Common/Traits/Buildings/RepairableBuilding.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/OpenRA.Mods.Common/Traits/Buildings/RepairableBuilding.cs b/OpenRA.Mods.Common/Traits/Buildings/RepairableBuilding.cs index 8f5028f11b..4718b7ba87 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/RepairableBuilding.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/RepairableBuilding.cs @@ -34,15 +34,18 @@ namespace OpenRA.Mods.Common.Traits { [Sync] public int RepairersHash { get { return Repairers.Aggregate(0, (code, player) => code ^ Sync.HashPlayer(player)); } } - public List Repairers = new List(); + public readonly List Repairers = new List(); readonly Health health; public bool RepairActive = false; + readonly Predicate isNotActiveAlly; + public RepairableBuilding(Actor self, RepairableBuildingInfo info) : base(info) { health = self.Trait(); + isNotActiveAlly = player => player.WinState != WinState.Undefined || player.Stances[self.Owner] != Stance.Ally; } public void RepairBuilding(Actor self, Player player) @@ -81,8 +84,7 @@ namespace OpenRA.Mods.Common.Traits if (remainingTicks == 0) { - Repairers = Repairers.Where(player => player.WinState == WinState.Undefined - && player.Stances[self.Owner] == Stance.Ally).ToList(); + Repairers.RemoveAll(isNotActiveAlly); // If after the previous operation there's no repairers left, stop if (!Repairers.Any()) return;