Cache results of TraitsImplementing calls.
If a class is caching the TraitsImplementing enumerable, instead cache the results of enumerating it to an array. The avoids having to enumerate the sequence each time it is needed.
This commit is contained in:
@@ -17,12 +17,12 @@ namespace OpenRA.Mods.Common.Activities
|
||||
{
|
||||
public class Rearm : Activity
|
||||
{
|
||||
readonly IEnumerable<AmmoPool> ammoPools;
|
||||
readonly AmmoPool[] ammoPools;
|
||||
readonly Dictionary<AmmoPool, int> ammoPoolsReloadTimes;
|
||||
|
||||
public Rearm(Actor self)
|
||||
{
|
||||
ammoPools = self.TraitsImplementing<AmmoPool>().Where(p => !p.Info.SelfReloads);
|
||||
ammoPools = self.TraitsImplementing<AmmoPool>().Where(p => !p.Info.SelfReloads).ToArray();
|
||||
|
||||
if (ammoPools == null)
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user