Skip to content

Commit

Permalink
Use length checks rather than .Any() (#6357)
Browse files Browse the repository at this point in the history
  • Loading branch information
benaadams authored Dec 12, 2023
1 parent 9df511b commit 2af3d8f
Show file tree
Hide file tree
Showing 16 changed files with 20 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ bool IBlockProducer.IsProducingBlocks(ulong? maxProducingInterval)
// Assemble the voting snapshot to check which votes make sense
Snapshot snapshot = _snapshotManager.GetOrCreateSnapshot(number - 1, parentHeader.Hash);
bool isEpochBlock = (ulong)number % 30000 == 0;
if (!isEpochBlock && _proposals.Any())
if (!isEpochBlock && !_proposals.IsEmpty)
{
// Gather all the proposals that make sense voting on
List<Address> addresses = new();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static IReadOnlyList<T> AllValuesCombinations<T>() where T : struct, Enum
// This bit converts to int[]
IReadOnlyList<T> values = FastEnum.GetValues<T>();

if (!typeof(T).GetCustomAttributes(typeof(FlagsAttribute), false).Any())
if (typeof(T).GetCustomAttributes(typeof(FlagsAttribute), false).Length == 0)
{
// We don't have flags so just return the result of GetValues
return values;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ protected virtual void Execute(Transaction tx, BlockExecutionContext blCtx, ITxT
}
else
{
LogEntry[] logs = substate.Logs.Any() ? substate.Logs.ToArray() : Array.Empty<LogEntry>();
LogEntry[] logs = substate.Logs.Count != 0 ? substate.Logs.ToArray() : Array.Empty<LogEntry>();
tracer.MarkAsSuccess(env.ExecutingAccount, spentGas, substate.Output.ToArray(), logs, stateRoot);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ bool BundleLimitTriggerCondition(BlockProductionEventArgs e)
return new MevBlockProducer.MevBlockProducerInfo(producer, manualTrigger, new BeneficiaryTracer());
}

int megabundleProducerCount = _relayAddresses.Any() ? 1 : 0;
int megabundleProducerCount = _relayAddresses.Length != 0 ? 1 : 0;
List<MevBlockProducer.MevBlockProducerInfo> blockProducers =
new(_maxMergedBundles + megabundleProducerCount + 1);

Expand Down
6 changes: 3 additions & 3 deletions src/Nethermind/Nethermind.Network.Discovery/DiscoveryApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ private async Task OnChannelActivated(CancellationToken cancellationToken)

//Check if we were able to communicate with any trusted nodes or persisted nodes
//if so no need to replay bootstrapping, we can start discovery process
if (_discoveryManager.GetOrAddNodeLifecycleManagers(x => x.State == NodeLifecycleState.Active).Any())
if (_discoveryManager.GetOrAddNodeLifecycleManagers(x => x.State == NodeLifecycleState.Active).Count != 0)
{
break;
}
Expand Down Expand Up @@ -347,7 +347,7 @@ private async Task StopUdpChannelAsync()
private async Task<bool> InitializeBootnodes(CancellationToken cancellationToken)
{
NetworkNode[] bootnodes = NetworkNode.ParseNodes(_discoveryConfig.Bootnodes, _logger);
if (!bootnodes.Any())
if (bootnodes.Length == 0)
{
if (_logger.IsWarn) _logger.Warn("No bootnodes specified in configuration");
return true;
Expand Down Expand Up @@ -389,7 +389,7 @@ private async Task<bool> InitializeBootnodes(CancellationToken cancellationToken
break;
}

if (_discoveryManager.GetOrAddNodeLifecycleManagers(x => x.State == NodeLifecycleState.Active).Any())
if (_discoveryManager.GetOrAddNodeLifecycleManagers(x => x.State == NodeLifecycleState.Active).Count != 0)
{
if (_logger.IsTrace)
_logger.Trace(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public NeighborsMsg(PublicKey farPublicKey, long expirationTime, Node[] nodes) :

public override string ToString()
{
return base.ToString() + $", Nodes: {(Nodes.Any() ? string.Join(",", Nodes.Select(x => x.ToString())) : "empty")}";
return base.ToString() + $", Nodes: {(Nodes.Length != 0 ? string.Join(",", Nodes.Select(x => x.ToString())) : "empty")}";
}

public override MsgType MsgType => MsgType.Neighbors;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void Serialize(IByteBuffer byteBuffer, NeighborsMsg msg)
PrepareBufferForSerialization(byteBuffer, totalLength, (byte)msg.MsgType);
NettyRlpStream stream = new(byteBuffer);
stream.StartSequence(contentLength);
if (msg.Nodes.Any())
if (msg.Nodes.Length != 0)
{
stream.StartSequence(nodesContentLength);
for (int i = 0; i < msg.Nodes.Length; i++)
Expand Down Expand Up @@ -100,7 +100,7 @@ public int GetLength(NeighborsMsg msg, out int contentLength)
{
int nodesContentLength = 0;
int contentLength = 0;
if (msg.Nodes.Any())
if (msg.Nodes.Length != 0)
{
contentLength += GetNodesLength(msg.Nodes, out nodesContentLength);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Nethermind/Nethermind.Network.Test/Rlpx/HobbitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ private Packet Run(Packet packet, StackType inbound, StackType outbound, bool fr
embeddedChannel.WriteOutbound(packet);
}

while (embeddedChannel.OutboundMessages.Any())
while (embeddedChannel.OutboundMessages.Count != 0)
{
IByteBuffer encodedPacket = embeddedChannel.ReadOutbound<IByteBuffer>();
embeddedChannel.WriteInbound(encodedPacket);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public IByteBuffer Decode(IByteBuffer input, bool throwOnCorruptedFrames = true)
}
}

if (result.Any())
if (result.Count != 0)
{
return (IByteBuffer)result[0];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public ZeroPacket Decode(IByteBuffer input)
base.Decode(_context, input, result);
}

if (!result.Any())
if (result.Count == 0)
{
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Nethermind/Nethermind.Network/NodesLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private void LoadPeersFromDb(List<Node> peers)

private void LoadConfigPeers(List<Node> peers, string? enodesString, Action<Node> nodeUpdate)
{
if (enodesString is null || !enodesString.Any())
if (enodesString is null || enodesString.Length == 0)
{
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Nethermind/Nethermind.Network/P2P/Session.cs
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ bool ShouldDisconnectStaticNode()

if (_logger.IsDebug) _logger.Debug($"{this} initiating disconnect because {disconnectReason}, details: {details}");
//Trigger disconnect on each protocol handler (if p2p is initialized it will send disconnect message to the peer)
if (_protocols.Any())
if (!_protocols.IsEmpty)
{
foreach (IProtocolHandler protocolHandler in _protocols.Values)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Nethermind/Nethermind.Network/PeerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,7 @@ private void DeactivatePeerIfDisconnected(Peer peer, string reason)

private string GetIncompatibleDesc(IReadOnlyCollection<Peer> incompatibleNodes)
{
if (!incompatibleNodes.Any())
if (incompatibleNodes.Count == 0)
{
return "0";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public override Task<WebSocketReceiveResult> ReceiveAsync(ArraySegment<byte> buf
}
}

if (!_receiveResults.Any() && ReturnTaskWithFaultOnEmptyQueue)
if (_receiveResults.Count == 0 && ReturnTaskWithFaultOnEmptyQueue)
{
Task<WebSocketReceiveResult> a = new Task<WebSocketReceiveResult>(() => throw new Exception());
a.Start();
Expand Down
2 changes: 1 addition & 1 deletion src/Nethermind/Nethermind.Trie.Test/TrieTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,7 @@ public void Fuzz_accounts_with_reorganizations(

rootQueue.Clear();
Stack<Hash256> stackCopy = new();
while (rootStack.Any())
while (rootStack.Count != 0)
{
stackCopy.Push(rootStack.Pop());
}
Expand Down
4 changes: 2 additions & 2 deletions src/Nethermind/Nethermind.TxPool/TxPoolInfoProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ public TxPoolInfo GetInfo()
}
}

if (pending.Any())
if (pending.Count != 0)
{
pendingTransactions[address] = pending;
}

if (queued.Any())
if (queued.Count != 0)
{
queuedTransactions[address] = queued;
}
Expand Down

0 comments on commit 2af3d8f

Please sign in to comment.