Avoid allocations when generating RadarSignatureCells.

The RadarWidget can supply a reusable buffer to each trait to avoid individual traits having to return new enumerables. Additionally, this allows the two traits to avoid LINQ and further allocations as they can manually enumerate and populate the buffer themselves.
This commit is contained in:
RoosterDragon
2017-11-23 19:00:28 +00:00
committed by abcdefg30
parent c69df4eedf
commit 0899d02377
4 changed files with 17 additions and 17 deletions

View File

@@ -272,9 +272,11 @@ namespace OpenRA.Mods.Common.Traits
return nodes;
}
public IEnumerable<Pair<CPos, Color>> RadarSignatureCells(Actor self)
public void PopulateRadarSignatureCells(Actor self, List<Pair<CPos, Color>> destinationBuffer)
{
return cellMap.SelectMany(c => c.Value.Select(p => Pair.New(c.Key, p.Owner.Color.RGB)));
foreach (var previewsForCell in cellMap)
foreach (var preview in previewsForCell.Value)
destinationBuffer.Add(Pair.New(previewsForCell.Key, preview.Owner.Color.RGB));
}
}
}