Prefer `List.Find` over `IEnumerable.FirstOrDefault`
Native type operations are faster and in this case it worth it.
MODIFY
WalletWasabi/WabiSabi/Backend/Rounds/Arena.cs
WalletWasabi/WabiSabi/Backend/Rounds/Arena.cs
@@ -419,7 +419,7 @@ namespace WalletWasabi.WabiSabi.Backend.Rounds
throw new WabiSabiProtocolException(WabiSabiProtocolErrorCode.RoundNotFound, $"Round ({request.RoundId}) not found.");
}
- if (round.Alices.FirstOrDefault(a => a.Id == request.AliceId) is not Alice alice)
+ if (round.Alices.Find(a => a.Id == request.AliceId) is not Alice alice)
{
throw new WabiSabiProtocolException(WabiSabiProtocolErrorCode.AliceNotFound, $"Round ({request.RoundId}): Alice id ({request.AliceId}).");
}
@@ -464,7 +464,7 @@ namespace WalletWasabi.WabiSabi.Backend.Rounds
throw new WabiSabiProtocolException(WabiSabiProtocolErrorCode.WrongPhase, $"Round ({request.RoundId}): Wrong phase ({round.Phase}).");
}
- alice = round.Alices.FirstOrDefault(x => x.Id == request.AliceId);
+ alice = round.Alices.Find(x => x.Id == request.AliceId);
if (alice is null)
{
throw new WabiSabiProtocolException(WabiSabiProtocolErrorCode.AliceNotFound, $"Round ({request.RoundId}): Alice ({request.AliceId}) not found.");
@@ -499,7 +499,7 @@ namespace WalletWasabi.WabiSabi.Backend.Rounds
using (await AsyncLock.LockAsync(cancellationToken).ConfigureAwait(false))
{
- if (round.Alices.FirstOrDefault(x => x.Id == request.AliceId) != alice)
+ if (round.Alices.Find(x => x.Id == request.AliceId) != alice)
{
throw new WabiSabiProtocolException(WabiSabiProtocolErrorCode.AliceNotFound, $"Round ({request.RoundId}): Alice ({request.AliceId}) not found.");
}

Prefer `List.Find` over `IEnumerable.FirstOrDefault`

Native type operations are faster and in this case it worth it.