Add FirstEnabledTraitOrDefault helper method.

This avoids the allocations caused by LINQ when using traits.FirstOrDefault(Exts.IsTraitEnabled). This is important in FrozenActorLayer.RefreshState which is called very often. We apply the new helper method to all areas using the old pattern. An overload that takes an array allows arrays to be enumerated without causing allocations.
This commit is contained in:
RoosterDragon
2017-11-17 19:10:03 +00:00
committed by Paul Chote
parent cb670d83b3
commit 7a7eed4fb7
8 changed files with 32 additions and 12 deletions

View File

@@ -235,7 +235,7 @@ namespace OpenRA.Mods.Common.Widgets
if (underCursor != null)
{
ActorTooltip = underCursor.TraitsImplementing<ITooltip>().FirstOrDefault(Exts.IsTraitEnabled);
ActorTooltip = underCursor.TraitsImplementing<ITooltip>().FirstEnabledTraitOrDefault();
if (ActorTooltip != null)
{
ActorTooltipExtra = underCursor.TraitsImplementing<IProvideTooltipInfo>().ToArray();