Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 529f60e

Browse files
authored
Change a few more uses of new T[] with a span (#93292)
1 parent da15b03 commit 529f60e

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

src/libraries/System.Linq/src/System/Linq/Range.SpeedOpt.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ private static void Fill(Span<int> destination, int value)
4545
Vector<int>.Count <= 8 &&
4646
destination.Length >= Vector<int>.Count)
4747
{
48-
Vector<int> init = new Vector<int>((ReadOnlySpan<int>)new int[] { 0, 1, 2, 3, 4, 5, 6, 7 });
48+
Vector<int> init = new Vector<int>((ReadOnlySpan<int>)[0, 1, 2, 3, 4, 5, 6, 7]);
4949
Vector<int> current = new Vector<int>(value) + init;
5050
Vector<int> increment = new Vector<int>(Vector<int>.Count);
5151

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,18 @@ namespace System.Net
2121
/// </devdoc>
2222
public class IPAddress : ISpanFormattable, ISpanParsable<IPAddress>, IUtf8SpanFormattable
2323
{
24-
public static readonly IPAddress Any = new ReadOnlyIPAddress(new byte[] { 0, 0, 0, 0 });
25-
public static readonly IPAddress Loopback = new ReadOnlyIPAddress(new byte[] { 127, 0, 0, 1 });
26-
public static readonly IPAddress Broadcast = new ReadOnlyIPAddress(new byte[] { 255, 255, 255, 255 });
24+
public static readonly IPAddress Any = new ReadOnlyIPAddress([0, 0, 0, 0]);
25+
public static readonly IPAddress Loopback = new ReadOnlyIPAddress([127, 0, 0, 1]);
26+
public static readonly IPAddress Broadcast = new ReadOnlyIPAddress([255, 255, 255, 255]);
2727
public static readonly IPAddress None = Broadcast;
2828

2929
internal const uint LoopbackMaskHostOrder = 0xFF000000;
3030

31-
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);
32-
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);
31+
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);
32+
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);
3333
public static readonly IPAddress IPv6None = IPv6Any;
3434

35-
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);
35+
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);
3636

3737
/// <summary>
3838
/// For IPv4 addresses, this field stores the Address.

src/libraries/System.Private.CoreLib/src/System/Text/UTF32Encoding.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,8 +1122,8 @@ public override byte[] GetPreamble()
11221122
public override ReadOnlySpan<byte> Preamble =>
11231123
GetType() != typeof(UTF32Encoding) ? new ReadOnlySpan<byte>(GetPreamble()) : // in case a derived UTF32Encoding overrode GetPreamble
11241124
!_emitUTF32ByteOrderMark ? default :
1125-
_bigEndian ? (ReadOnlySpan<byte>)new byte[4] { 0x00, 0x00, 0xFE, 0xFF } : // uses C# compiler's optimization for static byte[] data
1126-
(ReadOnlySpan<byte>)new byte[4] { 0xFF, 0xFE, 0x00, 0x00 };
1125+
_bigEndian ? [0x00, 0x00, 0xFE, 0xFF] :
1126+
[0xFF, 0xFE, 0x00, 0x00];
11271127

11281128
public override bool Equals([NotNullWhen(true)] object? value)
11291129
{

src/libraries/System.Private.CoreLib/src/System/Text/UnicodeEncoding.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1746,8 +1746,8 @@ public override byte[] GetPreamble()
17461746
public override ReadOnlySpan<byte> Preamble =>
17471747
GetType() != typeof(UnicodeEncoding) ? new ReadOnlySpan<byte>(GetPreamble()) : // in case a derived UnicodeEncoding overrode GetPreamble
17481748
!byteOrderMark ? default :
1749-
bigEndian ? (ReadOnlySpan<byte>)new byte[2] { 0xfe, 0xff } : // uses C# compiler's optimization for static byte[] data
1750-
(ReadOnlySpan<byte>)new byte[2] { 0xff, 0xfe };
1749+
bigEndian ? [0xfe, 0xff] :
1750+
[0xff, 0xfe];
17511751

17521752
public override int GetMaxByteCount(int charCount)
17531753
{

0 commit comments

Comments
 (0)