OccupiedCells and TargetableCells must return arrays, not just enumerables.
This allows callers to efficiently enumerate these returned collections without the allocation and overhead imposed by the IEnumerable interface. All implementations were already returning arrays, so this only required a signature change.
This commit is contained in:
committed by
Pavel Penev
parent
da036c5728
commit
62ab6ae6f1
@@ -460,7 +460,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
get { return Util.ApplyPercentageModifiers(Info.Speed, speedModifiers); }
|
||||
}
|
||||
|
||||
public IEnumerable<Pair<CPos, SubCell>> OccupiedCells() { return NoCells; }
|
||||
public Pair<CPos, SubCell>[] OccupiedCells() { return NoCells; }
|
||||
|
||||
public WVec FlyStep(int facing)
|
||||
{
|
||||
|
||||
@@ -291,9 +291,9 @@ namespace OpenRA.Mods.Common.Traits
|
||||
SkipMakeAnimation = init.Contains<SkipMakeAnimsInit>();
|
||||
}
|
||||
|
||||
public IEnumerable<Pair<CPos, SubCell>> OccupiedCells() { return occupiedCells; }
|
||||
public Pair<CPos, SubCell>[] OccupiedCells() { return occupiedCells; }
|
||||
|
||||
IEnumerable<Pair<CPos, SubCell>> ITargetableCells.TargetableCells() { return targetableCells; }
|
||||
Pair<CPos, SubCell>[] ITargetableCells.TargetableCells() { return targetableCells; }
|
||||
|
||||
void INotifyCreated.Created(Actor self)
|
||||
{
|
||||
|
||||
@@ -160,7 +160,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
}
|
||||
|
||||
public CPos TopLeft { get { return Location; } }
|
||||
public IEnumerable<Pair<CPos, SubCell>> OccupiedCells() { return new[] { Pair.New(Location, SubCell.FullCell) }; }
|
||||
public Pair<CPos, SubCell>[] OccupiedCells() { return new[] { Pair.New(Location, SubCell.FullCell) }; }
|
||||
|
||||
public WPos CenterPosition { get; private set; }
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
self.QueueActivity(new Drag(self, CenterPosition, finalPosition, distance / dragSpeed));
|
||||
}
|
||||
|
||||
public IEnumerable<Pair<CPos, SubCell>> OccupiedCells() { return new[] { Pair.New(TopLeft, SubCell.FullCell) }; }
|
||||
public 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)
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[Sync] readonly CPos location;
|
||||
[Sync] readonly WPos position;
|
||||
readonly IEnumerable<Pair<CPos, SubCell>> occupied;
|
||||
readonly Pair<CPos, SubCell>[] occupied;
|
||||
|
||||
public Immobile(ActorInitializer init, ImmobileInfo info)
|
||||
{
|
||||
@@ -50,7 +50,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public CPos TopLeft { get { return location; } }
|
||||
public WPos CenterPosition { get { return position; } }
|
||||
public IEnumerable<Pair<CPos, SubCell>> OccupiedCells() { return occupied; }
|
||||
public Pair<CPos, SubCell>[] OccupiedCells() { return occupied; }
|
||||
|
||||
void INotifyAddedToWorld.AddedToWorld(Actor self)
|
||||
{
|
||||
|
||||
@@ -665,7 +665,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public CPos TopLeft { get { return ToCell; } }
|
||||
|
||||
public IEnumerable<Pair<CPos, SubCell>> OccupiedCells()
|
||||
public Pair<CPos, SubCell>[] OccupiedCells()
|
||||
{
|
||||
if (FromCell == ToCell)
|
||||
return new[] { Pair.New(FromCell, FromSubCell) };
|
||||
|
||||
Reference in New Issue
Block a user