Use a BitSet for representing target types.
- Rename Bits<T> to BitSet<T>. - Implement set based helpers for BitSet<T>. - When representing TargetTypes of ITargetable in various traits, use a BitSet<TargetableType> instead of HashSet<string> for better performance & reduced memory usage. - Fix FieldLoader to trim input values when generating a BitSet<T>. - Require T in BitSet<T> and BitSetAllocator<T> to be a class since it's just a marker value. This allows the JIT to instantiate generic code for these classes once, as they don't benefit from specialized code for T. (Typically JITs will generate shared code for all reference types, and unique code for every value type encountered).
This commit is contained in:
@@ -36,7 +36,7 @@ namespace OpenRA.Traits
|
||||
readonly Shroud shroud;
|
||||
|
||||
public Player Owner { get; private set; }
|
||||
public HashSet<string> TargetTypes { get; private set; }
|
||||
public BitSet<TargetableType> TargetTypes { get; private set; }
|
||||
|
||||
public ITooltipInfo TooltipInfo { get; private set; }
|
||||
public Player TooltipOwner { get; private set; }
|
||||
@@ -84,7 +84,6 @@ namespace OpenRA.Traits
|
||||
footprint.Select(p => shroud.Contains(p).ToString()).JoinWith("|")));
|
||||
|
||||
CenterPosition = actor.CenterPosition;
|
||||
TargetTypes = new HashSet<string>();
|
||||
|
||||
tooltips = actor.TraitsImplementing<ITooltip>().ToArray();
|
||||
health = actor.TraitOrDefault<IHealth>();
|
||||
@@ -101,10 +100,7 @@ namespace OpenRA.Traits
|
||||
public void RefreshState()
|
||||
{
|
||||
Owner = actor.Owner;
|
||||
|
||||
// PERF: Reuse collection to avoid allocations.
|
||||
TargetTypes.Clear();
|
||||
TargetTypes.UnionWith(actor.GetEnabledTargetTypes());
|
||||
TargetTypes = actor.GetEnabledTargetTypes();
|
||||
|
||||
if (health != null)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user