diff --git a/OpenRA.Mods.Common/Traits/Radar/AppearsOnRadar.cs b/OpenRA.Mods.Common/Traits/Radar/AppearsOnRadar.cs index c846c9fcd9..c583986495 100644 --- a/OpenRA.Mods.Common/Traits/Radar/AppearsOnRadar.cs +++ b/OpenRA.Mods.Common/Traits/Radar/AppearsOnRadar.cs @@ -9,6 +9,7 @@ */ #endregion +using System; using System.Collections.Generic; using System.Drawing; using System.Linq; @@ -29,6 +30,9 @@ namespace OpenRA.Mods.Common.Traits.Radar readonly AppearsOnRadarInfo info; IRadarColorModifier modifier; + Color currentColor = Color.Transparent; + Func, Pair> cellToSignature; + public AppearsOnRadar(AppearsOnRadarInfo info) { this.info = info; @@ -48,7 +52,14 @@ namespace OpenRA.Mods.Common.Traits.Radar if (info.UseLocation) return new[] { Pair.New(self.Location, color) }; - return self.OccupiesSpace.OccupiedCells().Select(c => Pair.New(c.First, color)); + // PERF: Cache cellToSignature delegate to avoid allocations as color does not change often. + if (currentColor != color) + { + currentColor = color; + cellToSignature = c => Pair.New(c.First, color); + } + + return self.OccupiesSpace.OccupiedCells().Select(cellToSignature); } } } \ No newline at end of file