Skip to content

Commit d2e830a

Browse files
committed
use collection expressions to init spans where possible
1 parent 33e49a9 commit d2e830a

File tree

23 files changed

+102
-115
lines changed

23 files changed

+102
-115
lines changed

src/System.Windows.Forms.Design/src/System/ComponentModel/Design/Serialization/CodeDomSerializerBase.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1425,8 +1425,8 @@ private static object ExecuteBinaryOperator(IConvertible left, IConvertible righ
14251425
TypeCode rightType = right.GetTypeCode();
14261426

14271427
// The compatible types are listed in order from lowest bitness to highest. We must operate on the highest bitness to keep fidelity.
1428-
ReadOnlySpan<TypeCode> compatibleTypes = new TypeCode[]
1429-
{
1428+
ReadOnlySpan<TypeCode> compatibleTypes =
1429+
[
14301430
TypeCode.Byte,
14311431
TypeCode.Char,
14321432
TypeCode.Int16,
@@ -1435,7 +1435,7 @@ private static object ExecuteBinaryOperator(IConvertible left, IConvertible righ
14351435
TypeCode.UInt32,
14361436
TypeCode.Int64,
14371437
TypeCode.UInt64
1438-
};
1438+
];
14391439

14401440
int leftTypeIndex = -1;
14411441
int rightTypeIndex = -1;

src/System.Windows.Forms.Design/src/System/Resources/Tools/StronglyTypedResourceBuilder.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ public static partial class StronglyTypedResourceBuilder
4747
private const string CultureInfoPropertyName = "Culture";
4848

4949
// When fixing up identifiers, we will replace all these chars with ReplacementChar ('_').
50-
private static ReadOnlySpan<char> CharsToReplace => new char[]
51-
{
50+
private static ReadOnlySpan<char> CharsToReplace =>
51+
[
5252
' ', '\u00A0' /* non-breaking space */, '.', ',', ';', '|', '~', '@', '#', '%', '^', '&', '*', '+', '-',
5353
'/', '\\', '<', '>', '?', '[', ']', '(', ')', '{', '}', '\"', '\'', ':', '!'
54-
};
54+
];
5555

5656
private const char ReplacementChar = '_';
5757

src/System.Windows.Forms.Primitives/src/Microsoft/VisualStudio/Shell/ICategorizeProperties.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ static ref readonly Guid IComIID.Guid
1717
[MethodImpl(MethodImplOptions.AggressiveInlining)]
1818
get
1919
{
20-
ReadOnlySpan<byte> data = new byte[]
21-
{
20+
ReadOnlySpan<byte> data =
21+
[
2222
0x10, 0xfc, 0x07, 0x4d,
2323
0x31, 0xf9,
2424
0xce, 0x11,
2525
0xb0, 0x01, 0x00, 0xaa, 0x00, 0x68, 0x84, 0xe5
26-
};
26+
];
2727

2828
return ref Unsafe.As<byte, Guid>(ref MemoryMarshal.GetReference(data));
2929
}

src/System.Windows.Forms.Primitives/src/Microsoft/VisualStudio/Shell/IProvidePropertyBuilder.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ static ref readonly Guid IComIID.Guid
1717
[MethodImpl(MethodImplOptions.AggressiveInlining)]
1818
get
1919
{
20-
ReadOnlySpan<byte> data = new byte[]
21-
{
20+
ReadOnlySpan<byte> data =
21+
[
2222
0xd8, 0xc1, 0xc0, 0x33,
2323
0xcf, 0x33,
2424
0xd3, 0x11,
2525
0xbf, 0xf2, 0x00, 0xc0, 0x4f, 0x99, 0x02, 0x35
26-
};
26+
];
2727

2828
return ref Unsafe.As<byte, Guid>(ref MemoryMarshal.GetReference(data));
2929
}

src/System.Windows.Forms.Primitives/src/Microsoft/VisualStudio/Shell/IVSMDPerPropertyBrowsing.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ static ref readonly Guid IComIID.Guid
1818
[MethodImpl(MethodImplOptions.AggressiveInlining)]
1919
get
2020
{
21-
ReadOnlySpan<byte> data = new byte[]
22-
{
21+
ReadOnlySpan<byte> data =
22+
[
2323
0x3c, 0x68, 0x94, 0x74,
2424
0xa0, 0x37,
2525
0xd2, 0x11,
2626
0xa2, 0x73, 0x00, 0xc0, 0x4f, 0x8e, 0xf4, 0xFF
27-
};
27+
];
2828

2929
return ref Unsafe.As<byte, Guid>(ref MemoryMarshal.GetReference(data));
3030
}

src/System.Windows.Forms.Primitives/src/Microsoft/VisualStudio/Shell/IVsPerPropertyBrowsing.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ static ref readonly Guid IComIID.Guid
1717
[MethodImpl(MethodImplOptions.AggressiveInlining)]
1818
get
1919
{
20-
ReadOnlySpan<byte> data = new byte[]
21-
{
20+
ReadOnlySpan<byte> data =
21+
[
2222
0xa3, 0x10, 0xf5, 0x0f,
2323
0xa5, 0x5f,
2424
0xf1, 0x49,
2525
0x8c, 0xcc, 0x19, 0x0d, 0x71, 0x08, 0x3f, 0x3e
26-
};
26+
];
2727

2828
return ref Unsafe.As<byte, Guid>(ref MemoryMarshal.GetReference(data));
2929
}

src/System.Windows.Forms.Primitives/src/System/CharacterConstants.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ namespace System;
55

66
internal static class CharacterConstants
77
{
8-
public static ReadOnlySpan<char> NewLine => new char[] { '\n', '\r' };
8+
public static ReadOnlySpan<char> NewLine => [ '\n', '\r' ];
99
}

src/System.Windows.Forms.Primitives/src/System/Windows/Forms/Automation/UiaTextProvider.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,7 @@ internal static SafeArrayScope<double> BoundingRectangleAsArray(Rectangle bounds
116116
internal static VARIANT BoundingRectangleAsVariant(Rectangle bounds)
117117
=> (VARIANT)BoundingRectangleAsArray(bounds);
118118

119-
public int SendInput(int inputs, ref INPUT input, int size)
120-
{
121-
Span<INPUT> currentInput = stackalloc INPUT[1];
122-
currentInput[0] = input;
123-
124-
return (int)PInvoke.SendInput(currentInput, size);
125-
}
119+
public int SendInput(int inputs, ref INPUT input, int size) => (int)PInvoke.SendInput([input], size);
126120

127121
public unsafe int SendKeyboardInputVK(VIRTUAL_KEY vk, bool press)
128122
{

src/System.Windows.Forms.Primitives/src/System/Windows/Forms/BinaryFormat/BinaryFormattedObjectExtensions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,13 @@ static bool Get(BinaryFormattedObject format, [NotNullWhen(true)] out object? va
154154
value = Unsafe.As<ulong, DateTime>(ref ulongValue);
155155
return true;
156156
case TypeInfo.DecimalType:
157-
ReadOnlySpan<int> bits = stackalloc int[4]
158-
{
157+
ReadOnlySpan<int> bits =
158+
[
159159
(int)systemClass["lo"],
160160
(int)systemClass["mid"],
161161
(int)systemClass["hi"],
162162
(int)systemClass["flags"]
163-
};
163+
];
164164

165165
value = new decimal(bits);
166166
return true;

src/System.Windows.Forms.Primitives/src/System/Windows/Forms/DeviceContextExtensions.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,12 @@ internal static void DrawLine(this DeviceContextHdcScope hdc, HPEN hpen, Point p
5656
internal static void DrawLine(this HDC hdc, HPEN hpen, Point p1, Point p2)
5757
=> DrawLine(hdc, hpen, p1.X, p1.Y, p2.X, p2.Y);
5858

59-
internal static unsafe void DrawLine(this DeviceContextHdcScope hdc, HPEN hpen, int x1, int y1, int x2, int y2)
59+
internal static void DrawLine(this DeviceContextHdcScope hdc, HPEN hpen, int x1, int y1, int x2, int y2)
6060
=> DrawLine(hdc.HDC, hpen, x1, y1, x2, y2);
6161

62-
internal static unsafe void DrawLine(this HDC hdc, HPEN hpen, int x1, int y1, int x2, int y2)
62+
internal static void DrawLine(this HDC hdc, HPEN hpen, int x1, int y1, int x2, int y2)
6363
{
64-
ReadOnlySpan<int> lines = stackalloc int[] { x1, y1, x2, y2 };
65-
DrawLines(hdc, hpen, lines);
64+
DrawLines(hdc, hpen, [ x1, y1, x2, y2 ]);
6665
}
6766

6867
/// <summary>
@@ -71,7 +70,7 @@ internal static unsafe void DrawLine(this HDC hdc, HPEN hpen, int x1, int y1, in
7170
/// <param name="lines">
7271
/// MUST be a multiple of 4. Each group of 4 represents x1, y1, x2, y2.
7372
/// </param>
74-
internal static unsafe void DrawLines(this DeviceContextHdcScope hdc, HPEN hpen, ReadOnlySpan<int> lines)
73+
internal static void DrawLines(this DeviceContextHdcScope hdc, HPEN hpen, ReadOnlySpan<int> lines)
7574
=> DrawLines(hdc.HDC, hpen, lines);
7675

7776
/// <summary>

0 commit comments

Comments
 (0)