Prefer Min/MaxBy overloads to OrderBy().First() patterns

This commit is contained in:
RoosterDragon
2020-10-11 11:48:44 +01:00
committed by abcdefg30
parent bb116034c7
commit 094ccf76b0
3 changed files with 4 additions and 4 deletions

View File

@@ -282,7 +282,7 @@ namespace OpenRA.Graphics
// Try and find the closest cell // Try and find the closest cell
if (candidates.Count > 0) if (candidates.Count > 0)
{ {
return candidates.OrderBy(uv => return candidates.MinBy(uv =>
{ {
var p = map.CenterOfCell(uv.ToCPos(map.Grid.Type)); var p = map.CenterOfCell(uv.ToCPos(map.Grid.Type));
var s = worldRenderer.ScreenPxPosition(p); var s = worldRenderer.ScreenPxPosition(p);
@@ -290,7 +290,7 @@ namespace OpenRA.Graphics
var dy = Math.Abs(s.Y - world.Y); var dy = Math.Abs(s.Y - world.Y);
return dx * dx + dy * dy; return dx * dx + dy * dy;
}).First().ToCPos(map); }).ToCPos(map);
} }
// Something is very wrong, but lets return something that isn't completely bogus and hope the caller can recover // Something is very wrong, but lets return something that isn't completely bogus and hope the caller can recover

View File

@@ -43,7 +43,7 @@ namespace OpenRA.Network
if (lastClientFrame == -1) if (lastClientFrame == -1)
lastClientFrame = framePackets lastClientFrame = framePackets
.Where(x => x.Value.ContainsKey(clientId)) .Where(x => x.Value.ContainsKey(clientId))
.Select(x => x.Key).OrderBy(x => x).LastOrDefault(); .Select(x => x.Key).MaxByOrDefault(x => x);
clientQuitTimes[clientId] = lastClientFrame; clientQuitTimes[clientId] = lastClientFrame;
} }

View File

@@ -80,7 +80,7 @@ namespace OpenRA.Mods.Common.Traits.Render
if (IsTraitDisabled) if (IsTraitDisabled)
return; return;
var current = queue.AllQueued().Where(i => i.Started).OrderBy(i => i.RemainingTime).FirstOrDefault(); var current = queue.AllQueued().Where(i => i.Started).MinByOrDefault(i => i.RemainingTime);
value = current != null ? 1 - (float)current.RemainingCost / current.TotalCost : 0; value = current != null ? 1 - (float)current.RemainingCost / current.TotalCost : 0;
} }