Skip to content

Commit fde6b37

Browse files
Eliminate temporary byte array allocations in the static constructor of IPAddress. (#57397)
1 parent 3a5e41d commit fde6b37

File tree

1 file changed

+5
-5
lines changed
  • src/libraries/System.Net.Primitives/src/System/Net

1 file changed

+5
-5
lines changed

src/libraries/System.Net.Primitives/src/System/Net/IPAddress.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ public class IPAddress
2424

2525
internal const uint LoopbackMaskHostOrder = 0xFF000000;
2626

27-
public static readonly IPAddress IPv6Any = new IPAddress(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 0);
28-
public static readonly IPAddress IPv6Loopback = new IPAddress(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, 0);
29-
public static readonly IPAddress IPv6None = new IPAddress(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 0);
27+
public static readonly IPAddress IPv6Any = new IPAddress((ReadOnlySpan<byte>) new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 0);
28+
public static readonly IPAddress IPv6Loopback = new IPAddress((ReadOnlySpan<byte>) new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, 0);
29+
public static readonly IPAddress IPv6None = IPv6Any;
3030

31-
private static readonly IPAddress s_loopbackMappedToIPv6 = new IPAddress(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 127, 0, 0, 1 }, 0);
31+
private static readonly IPAddress s_loopbackMappedToIPv6 = new IPAddress((ReadOnlySpan<byte>) new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 127, 0, 0, 1 }, 0);
3232

3333
/// <summary>
3434
/// For IPv4 addresses, this field stores the Address.
@@ -644,7 +644,7 @@ public IPAddress MapToIPv4()
644644

645645
private sealed class ReadOnlyIPAddress : IPAddress
646646
{
647-
public ReadOnlyIPAddress(byte[] newAddress) : base(newAddress)
647+
public ReadOnlyIPAddress(ReadOnlySpan<byte> newAddress) : base(newAddress)
648648
{ }
649649
}
650650
}

0 commit comments

Comments
 (0)