Replace calls to Count() with Any() for performance and clarity
MODIFY
WalletWasabi.Backend/Controllers/BlockchainController.cs
WalletWasabi.Backend/Controllers/BlockchainController.cs
@@ -180,7 +180,7 @@ namespace WalletWasabi.Backend.Controllers
return NotFound($"Provided {nameof(bestKnownBlockHash)} is not found: {bestKnownBlockHash}.");
}
- if (filters.Count() == 0)
+ if (!filters.Any())
{
return NoContent();
}

MODIFY
WalletWasabi.Backend/Controllers/ChaumianCoinJoinController.cs
WalletWasabi.Backend/Controllers/ChaumianCoinJoinController.cs
@@ -87,7 +87,7 @@ namespace WalletWasabi.Backend.Controllers
|| string.IsNullOrWhiteSpace(request.BlindedOutputScriptHex)
|| string.IsNullOrWhiteSpace(request.ChangeOutputAddress)
|| request.Inputs == null
- || request.Inputs.Count() == 0
+ || !request.Inputs.Any()
|| request.Inputs.Any(x => x.Input == null
|| x.Input.Hash == null
|| string.IsNullOrWhiteSpace(x.Proof)))
@@ -329,7 +329,7 @@ namespace WalletWasabi.Backend.Controllers
{
IEnumerable<Alice> alicesToBan = await round.RemoveAlicesIfInputsSpentAsync(); // So ban only those who confirmed participation, yet spent their inputs.
- if (alicesToBan.Count() > 0)
+ if (alicesToBan.Any())
{
await Coordinator.UtxoReferee.BanUtxosAsync(1, DateTimeOffset.Now, alicesToBan.SelectMany(x => x.Inputs).Select(y => y.OutPoint).ToArray());
}
@@ -569,7 +569,7 @@ namespace WalletWasabi.Backend.Controllers
{
if (roundId <= 0
|| signatures == null
- || signatures.Count() <= 0
+ || !signatures.Any()
|| signatures.Any(x => x.Key < 0 || string.IsNullOrWhiteSpace(x.Value))
|| !ModelState.IsValid)
{

MODIFY
WalletWasabi/Extensions/HttpRequestMessageExtensions.cs
WalletWasabi/Extensions/HttpRequestMessageExtensions.cs
@@ -81,7 +81,7 @@ namespace System.Net.Http
var startLine = new RequestLine(me.Method, me.RequestUri, new HttpProtocol($"HTTP/{me.Version.Major}.{me.Version.Minor}")).ToString();
string headers = "";
- if (me.Headers != null && me.Headers.Count() != 0)
+ if (me.Headers != null && me.Headers.Any())
{
var headerSection = HeaderSection.CreateNew(me.Headers);
headers += headerSection.ToString(endWithTwoCRLF: false);
@@ -90,7 +90,7 @@ namespace System.Net.Http
string messageBody = "";
if (me.Content != null)
{
- if (me.Content.Headers != null && me.Content.Headers.Count() != 0)
+ if (me.Content.Headers != null && me.Content.Headers.Any())
{
var headerSection = HeaderSection.CreateNew(me.Content.Headers);
headers += headerSection.ToString(endWithTwoCRLF: false);

MODIFY
WalletWasabi/Extensions/HttpResponseMessageExtensions.cs
WalletWasabi/Extensions/HttpResponseMessageExtensions.cs
@@ -65,7 +65,7 @@ namespace System.Net.Http
var startLine = new StatusLine(new HttpProtocol($"HTTP/{me.Version.Major}.{me.Version.Minor}"), me.StatusCode).ToString();
var headers = "";
- if (me.Headers != null && me.Headers.Count() != 0)
+ if (me.Headers != null && me.Headers.Any())
{
var headerSection = HeaderSection.CreateNew(me.Headers);
headers += headerSection.ToString(endWithTwoCRLF: false);
@@ -74,7 +74,7 @@ namespace System.Net.Http
var messageBody = "";
if (me.Content != null)
{
- if (me.Content.Headers != null && me.Content.Headers.Count() != 0)
+ if (me.Content.Headers != null && me.Content.Headers.Any())
{
var headerSection = HeaderSection.CreateNew(me.Content.Headers);
headers += headerSection.ToString(endWithTwoCRLF: false);

MODIFY
WalletWasabi/Helpers/Guard.cs
WalletWasabi/Helpers/Guard.cs
@@ -53,7 +53,7 @@ namespace WalletWasabi.Helpers
{
NotNull(parameterName, value);
- if (value.Count() == 0)
+ if (!value.Any())
{
throw new ArgumentException("Parameter cannot be empty.", parameterName);
}
@@ -65,7 +65,7 @@ namespace WalletWasabi.Helpers
{
NotNull(parameterName, value);
- if (value.Count() == 0)
+ if (!value.Any())
{
throw new ArgumentException("Parameter cannot be empty.", parameterName);
}

MODIFY
WalletWasabi/Helpers/HttpMessageHelper.cs
WalletWasabi/Helpers/HttpMessageHelper.cs
@@ -492,7 +492,7 @@ namespace System.Net.Http
public static HttpContent GetDummyOrNullContent(HttpContentHeaders contentHeaders)
{
- if (contentHeaders != null && contentHeaders.Count() != 0)
+ if (contentHeaders != null && contentHeaders.Any())
{
return new ByteArrayContent(new byte[] { }); // dummy empty content
}
@@ -504,7 +504,7 @@ namespace System.Net.Http
public static void CopyHeaders(HttpHeaders source, HttpHeaders destination)
{
- if (source != null && source.Count() != 0)
+ if (source != null && source.Any())
{
foreach (var header in source)
{

MODIFY
WalletWasabi/Models/ChaumianCoinJoin/CcjRound.cs
WalletWasabi/Models/ChaumianCoinJoin/CcjRound.cs
@@ -400,7 +400,7 @@ namespace WalletWasabi.Models.ChaumianCoinJoin
IEnumerable<OutPoint> inputsToBan = alicesToBan1.SelectMany(x => x.Inputs).Select(y => y.OutPoint).Concat(alicesToBan2.SelectMany(x => x.Inputs).Select(y => y.OutPoint).ToArray()).Distinct();
- if (inputsToBan.Count() != 0)
+ if (inputsToBan.Any())
{
await UtxoReferee.BanUtxosAsync(1, DateTimeOffset.Now, inputsToBan.ToArray());
}

MODIFY
WalletWasabi/Services/CcjClient.cs
WalletWasabi/Services/CcjClient.cs
@@ -106,11 +106,11 @@ namespace WalletWasabi.Services
if (IsRunning == false) return;
// if mixing >= connConf: delay = new Random().Next(2, 7);
- if (State.GetActivelyMixingRounds().Count() > 0)
+ if (State.GetActivelyMixingRounds().Any())
{
delay = new Random().Next(2, 7);
}
- else if (Interlocked.Read(ref _frequentStatusProcessingIfNotMixing) == 1 || State.GetPassivelyMixingRounds().Count() > 0 || State.GetWaitingListCount() > 0)
+ else if (Interlocked.Read(ref _frequentStatusProcessingIfNotMixing) == 1 || State.GetPassivelyMixingRounds().Any()|| State.GetWaitingListCount() > 0)
{
double rand = double.Parse($"0.{new Random().Next(2, 8)}"); // randomly between every 0.2 * connConfTimeout - 7 and 0.8 * connConfTimeout
delay = Math.Max(0, (int)(rand * State.GetSmallestRegistrationTimeout() - 7));

MODIFY
WalletWasabi/Services/WalletService.cs
WalletWasabi/Services/WalletService.cs
@@ -300,7 +300,7 @@ namespace WalletWasabi.Services
// If double spend:
IEnumerable<SmartCoin> doubleSpends = Coins.Where(x => tx.Transaction.Inputs.Any(y => x.SpentOutputs.Select(z => z.ToOutPoint()).Contains(y.PrevOut)));
- if (doubleSpends.Count() > 0)
+ if (doubleSpends.Any())
{
if (tx.Height == Height.MemPool)
{

Replace calls to Count() with Any() for performance and clarity