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:
@@ -43,6 +43,7 @@ namespace OpenRA.Mods.Cnc.Traits
|
||||
public class GrantPrerequisiteChargeDrainPower : SupportPower, ITechTreePrerequisite, INotifyOwnerChanged
|
||||
{
|
||||
readonly GrantPrerequisiteChargeDrainPowerInfo info;
|
||||
readonly string[] prerequisites;
|
||||
TechTree techTree;
|
||||
bool active;
|
||||
|
||||
@@ -50,6 +51,7 @@ namespace OpenRA.Mods.Cnc.Traits
|
||||
: base(self, info)
|
||||
{
|
||||
this.info = info;
|
||||
prerequisites = new[] { info.Prerequisite };
|
||||
}
|
||||
|
||||
protected override void Created(Actor self)
|
||||
@@ -82,16 +84,7 @@ namespace OpenRA.Mods.Cnc.Traits
|
||||
techTree.ActorChanged(self);
|
||||
}
|
||||
|
||||
IEnumerable<string> ITechTreePrerequisite.ProvidesPrerequisites
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!active)
|
||||
yield break;
|
||||
|
||||
yield return info.Prerequisite;
|
||||
}
|
||||
}
|
||||
IEnumerable<string> ITechTreePrerequisite.ProvidesPrerequisites => active ? prerequisites : Enumerable.Empty<string>();
|
||||
|
||||
public class DischargeableSupportPowerInstance : SupportPowerInstance
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user