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:
@@ -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}!");
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user