Memory Changes part 2

* Slightly refactors RangeLists from the last Memory Changes MR, which fixes issue 61.

* Convert as many const size array iterators to span iterators as possible. When iterating over a const size array, every iteration created a Span, now only the first iteration does in most places.

* Now using object pooling for a few object types that were rapidly deleted and recreated.

* Converted a few flag checks to binary operations to save memory allocations.
This commit is contained in:
LotP
2025-08-26 15:30:12 -05:00
committed by KeatonTheBot
parent 01cb33f658
commit 171624e7f0
89 changed files with 2121 additions and 1157 deletions
@@ -30,21 +30,21 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres.Types
{
Port = IPAddress.HostToNetworkOrder(Port);
RawIpv4AddressNetworkEndianSwap(ref Address);
RawIpv4AddressNetworkEndianSwap(Address.AsSpan());
}
public void ToHostOrder()
{
Port = IPAddress.NetworkToHostOrder(Port);
RawIpv4AddressNetworkEndianSwap(ref Address);
RawIpv4AddressNetworkEndianSwap(Address.AsSpan());
}
public static void RawIpv4AddressNetworkEndianSwap(ref Array4<byte> address)
public static void RawIpv4AddressNetworkEndianSwap(Span<byte> address)
{
if (BitConverter.IsLittleEndian)
{
address.AsSpan().Reverse();
address.Reverse();
}
}
}
@@ -73,7 +73,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres.Types
{
// Nintendo hardcode 4 bytes in that case here.
Array4<byte> address = MemoryMarshal.Read<Array4<byte>>(buffer);
AddrInfo4.RawIpv4AddressNetworkEndianSwap(ref address);
AddrInfo4.RawIpv4AddressNetworkEndianSwap(address.AsSpan());
rawIPv4Address = address;
@@ -115,7 +115,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres.Types
else
{
Array4<byte> rawIPv4Address = RawIPv4Address.Value;
AddrInfo4.RawIpv4AddressNetworkEndianSwap(ref rawIPv4Address);
AddrInfo4.RawIpv4AddressNetworkEndianSwap(rawIPv4Address.AsSpan());
MemoryMarshal.Write(buffer, in rawIPv4Address);