Make OccupiedCells implementations return arrays.

Since there are only one or two items, it's cheaper to return a concrete collection and avoid the overhead of the compiler generated state machine.

This in particular speeds up Shroud.GetVisOrigins when dealing with Mobile.OccupiedCells, as the expensive CanEnterCell call is made only once rather than twice.
This commit is contained in:
RoosterDragon
2014-12-27 10:39:29 +00:00
parent 06226e8958
commit fe24304a21
3 changed files with 6 additions and 10 deletions

View File

@@ -60,7 +60,7 @@ namespace OpenRA.Mods.Common.Traits
self.QueueActivity(new Drag(self, CenterPosition, finalPosition, distance / dragSpeed));
}
public IEnumerable<Pair<CPos, SubCell>> OccupiedCells() { yield return Pair.New(TopLeft, SubCell.FullCell); }
public IEnumerable<Pair<CPos, SubCell>> OccupiedCells() { return new[] { Pair.New(TopLeft, SubCell.FullCell) }; }
public bool IsLeavingCell(CPos location, SubCell subCell = SubCell.Any) { return false; }
public SubCell GetValidSubCell(SubCell preferred = SubCell.Any) { return SubCell.FullCell; }
public SubCell GetAvailableSubCell(CPos cell, SubCell preferredSubCell = SubCell.Any, Actor ignoreActor = null, bool checkTransientActors = true)