Skip to content

Commit

Permalink
Change a few more uses of new T[] with a span
Browse files Browse the repository at this point in the history
  • Loading branch information
stephentoub committed Oct 11, 2023
1 parent 565ee96 commit 237f5f9
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private static void Fill(Span<int> destination, int value)
Vector<int>.Count <= 8 &&
destination.Length >= Vector<int>.Count)
{
Vector<int> init = new Vector<int>((ReadOnlySpan<int>)new int[] { 0, 1, 2, 3, 4, 5, 6, 7 });
Vector<int> init = new Vector<int>((ReadOnlySpan<int>)[0, 1, 2, 3, 4, 5, 6, 7]);
Vector<int> current = new Vector<int>(value) + init;
Vector<int> increment = new Vector<int>(Vector<int>.Count);

Expand Down
12 changes: 6 additions & 6 deletions src/libraries/System.Net.Primitives/src/System/Net/IPAddress.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@ namespace System.Net
/// </devdoc>
public class IPAddress : ISpanFormattable, ISpanParsable<IPAddress>, IUtf8SpanFormattable
{
public static readonly IPAddress Any = new ReadOnlyIPAddress(new byte[] { 0, 0, 0, 0 });
public static readonly IPAddress Loopback = new ReadOnlyIPAddress(new byte[] { 127, 0, 0, 1 });
public static readonly IPAddress Broadcast = new ReadOnlyIPAddress(new byte[] { 255, 255, 255, 255 });
public static readonly IPAddress Any = new ReadOnlyIPAddress([0, 0, 0, 0]);
public static readonly IPAddress Loopback = new ReadOnlyIPAddress([127, 0, 0, 1]);
public static readonly IPAddress Broadcast = new ReadOnlyIPAddress([255, 255, 255, 255]);
public static readonly IPAddress None = Broadcast;

internal const uint LoopbackMaskHostOrder = 0xFF000000;

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);
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);
public static readonly IPAddress IPv6Any = new IPAddress((ReadOnlySpan<byte>)[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 0);
public static readonly IPAddress IPv6Loopback = new IPAddress((ReadOnlySpan<byte>)[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], 0);
public static readonly IPAddress IPv6None = IPv6Any;

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);
private static readonly IPAddress s_loopbackMappedToIPv6 = new IPAddress((ReadOnlySpan<byte>)[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 127, 0, 0, 1], 0);

/// <summary>
/// For IPv4 addresses, this field stores the Address.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1122,8 +1122,8 @@ public override byte[] GetPreamble()
public override ReadOnlySpan<byte> Preamble =>
GetType() != typeof(UTF32Encoding) ? new ReadOnlySpan<byte>(GetPreamble()) : // in case a derived UTF32Encoding overrode GetPreamble
!_emitUTF32ByteOrderMark ? default :
_bigEndian ? (ReadOnlySpan<byte>)new byte[4] { 0x00, 0x00, 0xFE, 0xFF } : // uses C# compiler's optimization for static byte[] data
(ReadOnlySpan<byte>)new byte[4] { 0xFF, 0xFE, 0x00, 0x00 };
_bigEndian ? [0x00, 0x00, 0xFE, 0xFF] :
[0xFF, 0xFE, 0x00, 0x00];

public override bool Equals([NotNullWhen(true)] object? value)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1746,8 +1746,8 @@ public override byte[] GetPreamble()
public override ReadOnlySpan<byte> Preamble =>
GetType() != typeof(UnicodeEncoding) ? new ReadOnlySpan<byte>(GetPreamble()) : // in case a derived UnicodeEncoding overrode GetPreamble
!byteOrderMark ? default :
bigEndian ? (ReadOnlySpan<byte>)new byte[2] { 0xfe, 0xff } : // uses C# compiler's optimization for static byte[] data
(ReadOnlySpan<byte>)new byte[2] { 0xff, 0xfe };
bigEndian ? [0xfe, 0xff] :
[0xff, 0xfe];

public override int GetMaxByteCount(int charCount)
{
Expand Down

0 comments on commit 237f5f9

Please sign in to comment.