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:
@@ -84,7 +84,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (allProductionPaused)
|
||||
return;
|
||||
|
||||
var item = Queue.Find(i => !i.Paused);
|
||||
var item = Queue.FirstOrDefault(i => !i.Paused);
|
||||
if (item == null)
|
||||
return;
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Traits;
|
||||
@@ -34,7 +33,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
// TODO: This won't make sense for MP saves
|
||||
var localPlayer = worldRenderer.World.LocalPlayer;
|
||||
if ((localPlayer != null && localPlayer.PlayerActor != self) ||
|
||||
(localPlayer == null && self.Owner != Array.Find(self.World.Players, p => p.IsBot)))
|
||||
(localPlayer == null && self.Owner != self.World.Players.FirstOrDefault(p => p.IsBot)))
|
||||
return null;
|
||||
|
||||
var nodes = new List<MiniYamlNode>()
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
CancelUnbuildableItems();
|
||||
|
||||
var item = Queue.Find(i => !i.Paused);
|
||||
var item = Queue.FirstOrDefault(i => !i.Paused);
|
||||
if (item == null)
|
||||
return;
|
||||
|
||||
|
||||
@@ -175,7 +175,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
.Where(p => p.AcceptsPlug(plugInfo.Type))
|
||||
.ToList();
|
||||
|
||||
var pluggable = pluggables.Find(p => a.Location + p.Info.Offset == targetLocation)
|
||||
var pluggable = pluggables.FirstOrDefault(p => a.Location + p.Info.Offset == targetLocation)
|
||||
?? pluggables.FirstOrDefault();
|
||||
|
||||
if (pluggable == null)
|
||||
|
||||
@@ -515,7 +515,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
protected virtual void PauseProduction(string itemName, bool paused)
|
||||
{
|
||||
Queue.Find(a => a.Item == itemName)?.Pause(paused);
|
||||
Queue.FirstOrDefault(a => a.Item == itemName)?.Pause(paused);
|
||||
}
|
||||
|
||||
protected virtual void CancelProduction(string itemName, uint numberToCancel)
|
||||
|
||||
Reference in New Issue
Block a user