Introduce FirstOrDefault extensions method for Array.Find and List.Find.

This allows the LINQ spelling to be used, but benefits from the performance improvement of the specific methods for these classes that provide the same result.
This commit is contained in:
RoosterDragon
2023-11-17 09:49:27 +00:00
committed by Gustas
parent acca837142
commit e6914f707a
54 changed files with 83 additions and 89 deletions

View File

@@ -9,7 +9,6 @@
*/
#endregion
using System;
using System.Linq;
using Eluant;
using OpenRA.Mods.Cnc.Activities;
@@ -33,7 +32,7 @@ namespace OpenRA.Mods.Cnc.Scripting
[Desc("Infiltrate the target actor.")]
public void Infiltrate(Actor target)
{
var infiltrates = Array.Find(infiltratesTraits, x => !x.IsTraitDisabled && x.Info.Types.Overlaps(target.GetEnabledTargetTypes()));
var infiltrates = infiltratesTraits.FirstOrDefault(x => !x.IsTraitDisabled && x.Info.Types.Overlaps(target.GetEnabledTargetTypes()));
if (infiltrates == null)
throw new LuaException($"{Self} tried to infiltrate invalid target {target}!");

View File

@@ -161,7 +161,7 @@ namespace OpenRA.Mods.Cnc.Traits
if (!available || order.ExtraData != 1)
return;
var power = Instances.Find(i => !i.IsTraitPaused);
var power = Instances.FirstOrDefault(i => !i.IsTraitPaused);
if (power == null)
return;