misc: chore: Use collection expressions in HLE project

This commit is contained in:
Evan Husted 2025-01-26 15:43:02 -06:00
parent 3c2f283ec7
commit 70b767ef60
72 changed files with 312 additions and 299 deletions

View file

@ -84,7 +84,7 @@ namespace Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator
NetworkConfig = networkConfig,
};
bool success = _parent.NetworkClient.CreateNetwork(request, _advertiseData ?? Array.Empty<byte>());
bool success = _parent.NetworkClient.CreateNetwork(request, _advertiseData ?? []);
return success ? ResultCode.Success : ResultCode.InvalidState;
}

View file

@ -163,7 +163,7 @@ namespace Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator
}
else
{
return Array.Empty<NodeLatestUpdate>();
return [];
}
}

View file

@ -56,7 +56,7 @@ namespace Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator
public NetworkInfo[] Scan(ushort channel, ScanFilter scanFilter)
{
Logger.Warning?.PrintMsg(LogClass.ServiceLdn, "Attempted to scan for networks, but Multiplayer is disabled!");
return Array.Empty<NetworkInfo>();
return [];
}
public void SetAdvertiseData(byte[] data) { }

View file

@ -28,7 +28,7 @@ namespace Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator.LdnMitm
private readonly Ssid _fakeSsid;
private ILdnTcpSocket _tcp;
private LdnProxyUdpServer _udp, _udp2;
private readonly List<LdnProxyTcpSession> _stations = new();
private readonly List<LdnProxyTcpSession> _stations = [];
private readonly Lock _lock = new();
private readonly AutoResetEvent _apConnected = new(false);
@ -340,10 +340,10 @@ namespace Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator.LdnMitm
if (_protocol.SendBroadcast(_udp, LanPacketType.Scan, DefaultPort) < 0)
{
return Array.Empty<NetworkInfo>();
return [];
}
List<NetworkInfo> outNetworkInfo = new();
List<NetworkInfo> outNetworkInfo = [];
foreach (KeyValuePair<ulong, NetworkInfo> item in _udp.GetScanResults())
{

View file

@ -162,7 +162,7 @@ namespace Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator.LdnMitm
public int SendBroadcast(ILdnSocket s, LanPacketType type, int port)
{
return SendPacket(s, type, Array.Empty<byte>(), new IPEndPoint(_discovery.LocalBroadcastAddr, port));
return SendPacket(s, type, [], new IPEndPoint(_discovery.LocalBroadcastAddr, port));
}
public int SendPacket(ILdnSocket s, LanPacketType type, byte[] data, EndPoint endPoint = null)
@ -231,7 +231,7 @@ namespace Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator.LdnMitm
private int Compress(byte[] input, out byte[] output)
{
List<byte> outputList = new();
List<byte> outputList = [];
int i = 0;
int maxCount = 0xFF;
@ -275,7 +275,7 @@ namespace Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator.LdnMitm
private int Decompress(byte[] input, out byte[] output)
{
List<byte> outputList = new();
List<byte> outputList = [];
int i = 0;
while (i < input.Length && outputList.Count < BufferSize)

View file

@ -40,7 +40,7 @@ namespace Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator.LdnRyu
private readonly RyuLdnProtocol _protocol;
private readonly NetworkTimeout _timeout;
private readonly List<NetworkInfo> _availableGames = new();
private readonly List<NetworkInfo> _availableGames = [];
private DisconnectReason _disconnectReason;
private P2pProxyServer _hostedProxy;
@ -109,7 +109,7 @@ namespace Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator.LdnRyu
ConnectAsync();
int index = WaitHandle.WaitAny(new WaitHandle[] { _connected, _error }, FailureTimeout);
int index = WaitHandle.WaitAny([_connected, _error], FailureTimeout);
if (IsConnected)
{
@ -326,7 +326,7 @@ namespace Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator.LdnRyu
SendAsync(_protocol.Encode(PacketId.Reject, new RejectRequest(disconnectReason, nodeId)));
int index = WaitHandle.WaitAny(new WaitHandle[] { _reject, _error }, InactiveTimeout);
int index = WaitHandle.WaitAny([_reject, _error], InactiveTimeout);
if (index == 0)
{
@ -566,13 +566,13 @@ namespace Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator.LdnRyu
SendAsync(_protocol.Encode(PacketId.Scan, scanFilter));
index = WaitHandle.WaitAny(new WaitHandle[] { _scan, _error }, ScanTimeout);
index = WaitHandle.WaitAny([_scan, _error], ScanTimeout);
}
if (index != 0)
{
// An error occurred or timeout. Write 0 games.
return Array.Empty<NetworkInfo>();
return [];
}
return _availableGames.ToArray();

View file

@ -7,7 +7,7 @@ namespace Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator.LdnRyu.Proxy
{
private const ushort EphemeralBase = 49152;
private readonly List<ushort> _ephemeralPorts = new();
private readonly List<ushort> _ephemeralPorts = [];
private readonly Lock _lock = new();

View file

@ -13,7 +13,7 @@ namespace Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator.LdnRyu.Proxy
public EndPoint LocalEndpoint { get; }
public IPAddress LocalAddress { get; }
private readonly List<LdnProxySocket> _sockets = new();
private readonly List<LdnProxySocket> _sockets = [];
private readonly Dictionary<ProtocolType, EphemeralPortPool> _ephemeralPorts = new();
private readonly IProxyClient _parent;

View file

@ -18,7 +18,7 @@ namespace Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator.LdnRyu.Proxy
private readonly LdnProxy _proxy;
private bool _isListening;
private readonly List<LdnProxySocket> _listenSockets = new();
private readonly List<LdnProxySocket> _listenSockets = [];
private readonly Queue<ProxyConnectRequest> _connectRequests = new();

View file

@ -41,9 +41,9 @@ namespace Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator.LdnRyu.Proxy
private NatDevice _natDevice;
private Mapping _portMapping;
private readonly List<P2pProxySession> _players = new();
private readonly List<P2pProxySession> _players = [];
private readonly List<ExternalProxyToken> _waitingTokens = new();
private readonly List<ExternalProxyToken> _waitingTokens = [];
private readonly AutoResetEvent _tokenEvent = new(false);
private uint _broadcastAddress;