TechTree.GatherOwnedPrerequisites performance improvements.
- Consuming methods cared only about the count and not the actual actors, so only counts the actors rather that creating lists. - ProvidesPrerequisites implementations return cached objects rather then allocating new enumerables on each call.
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
@@ -39,7 +40,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public class ProvidesPrerequisite : ConditionalTrait<ProvidesPrerequisiteInfo>, ITechTreePrerequisite, INotifyOwnerChanged, INotifyCreated
|
||||
{
|
||||
readonly string prerequisite;
|
||||
readonly string[] prerequisites;
|
||||
|
||||
bool enabled;
|
||||
TechTree techTree;
|
||||
@@ -48,24 +49,15 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public ProvidesPrerequisite(ActorInitializer init, ProvidesPrerequisiteInfo info)
|
||||
: base(info)
|
||||
{
|
||||
prerequisite = info.Prerequisite;
|
||||
|
||||
if (string.IsNullOrEmpty(prerequisite))
|
||||
prerequisite = init.Self.Info.Name;
|
||||
if (string.IsNullOrEmpty(info.Prerequisite))
|
||||
prerequisites = new[] { init.Self.Info.Name };
|
||||
else
|
||||
prerequisites = new[] { info.Prerequisite };
|
||||
|
||||
faction = init.GetValue<FactionInit, string>(init.Self.Owner.Faction.InternalName);
|
||||
}
|
||||
|
||||
public IEnumerable<string> ProvidesPrerequisites
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!enabled)
|
||||
yield break;
|
||||
|
||||
yield return prerequisite;
|
||||
}
|
||||
}
|
||||
public IEnumerable<string> ProvidesPrerequisites => enabled ? prerequisites : Enumerable.Empty<string>();
|
||||
|
||||
protected override void Created(Actor self)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user