Avoid LINQ in some Tick methods.

As Tick is called often, avoiding allocation overhead in these methods is useful.
This commit is contained in:
RoosterDragon
2017-12-15 19:26:09 +00:00
committed by reaperrr
parent 86f9b8807e
commit dd2ae9fe5e
3 changed files with 36 additions and 11 deletions

View File

@@ -172,9 +172,11 @@ namespace OpenRA.Traits
void ITick.Tick(Actor self)
{
ResourceCapacity = self.World.ActorsWithTrait<IStoreResources>()
.Where(a => a.Actor.Owner == owner)
.Sum(a => a.Trait.Capacity);
// PERF: Avoid LINQ.
ResourceCapacity = 0;
foreach (var tp in self.World.ActorsWithTrait<IStoreResources>())
if (tp.Actor.Owner == owner)
ResourceCapacity += tp.Trait.Capacity;
if (Resources > ResourceCapacity)
Resources = ResourceCapacity;