Replace arrays with sets.
In places where arrays were being treated as a set, just create a set directly. This reveals the intention of such collections better, and also improves performance by allowing set based methods to be used.
This commit is contained in:
@@ -27,7 +27,7 @@ namespace OpenRA.Traits
|
||||
public readonly PPos[] Footprint;
|
||||
public readonly WPos CenterPosition;
|
||||
public readonly Rectangle Bounds;
|
||||
public readonly string[] TargetTypes;
|
||||
public readonly HashSet<string> TargetTypes;
|
||||
readonly IRemoveFrozenActor[] removeFrozenActors;
|
||||
readonly Actor actor;
|
||||
readonly Shroud shroud;
|
||||
@@ -57,7 +57,7 @@ namespace OpenRA.Traits
|
||||
|
||||
CenterPosition = self.CenterPosition;
|
||||
Bounds = self.Bounds;
|
||||
TargetTypes = self.TraitsImplementing<ITargetable>().Where(Exts.IsTraitEnabled).SelectMany(t => t.TargetTypes).Distinct().ToArray();
|
||||
TargetTypes = self.TraitsImplementing<ITargetable>().Where(Exts.IsTraitEnabled).SelectMany(t => t.TargetTypes).ToHashSet();
|
||||
|
||||
UpdateVisibility();
|
||||
}
|
||||
|
||||
@@ -310,13 +310,13 @@ namespace OpenRA.Traits
|
||||
|
||||
public interface ITargetableInfo
|
||||
{
|
||||
string[] GetTargetTypes();
|
||||
HashSet<string> GetTargetTypes();
|
||||
}
|
||||
|
||||
public interface ITargetable
|
||||
{
|
||||
// Check IsTraitEnabled or !IsTraitDisabled first
|
||||
string[] TargetTypes { get; }
|
||||
HashSet<string> TargetTypes { get; }
|
||||
bool TargetableBy(Actor self, Actor byActor);
|
||||
bool RequiresForceFire { get; }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user