Skip to content

Commit 59e3fcf

Browse files
committed
rollback stackalloc changes
1 parent 7bbaa42 commit 59e3fcf

File tree

10 files changed

+75
-67
lines changed

10 files changed

+75
-67
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ internal static SafeArrayScope<double> BoundingRectangleAsArray(Rectangle bounds
114114

115115
public int SendInput(int inputs, ref INPUT input, int size)
116116
{
117-
Span<INPUT> currentInput = [input];
117+
Span<INPUT> currentInput = stackalloc INPUT[1];
118+
currentInput[0] = input;
118119

119120
return (int)PInvoke.SendInput(currentInput, size);
120121
}

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-
Span<int> bits =
158-
[
157+
Span<int> bits = stackalloc int[4]
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: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,13 @@ 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 void DrawLine(this DeviceContextHdcScope hdc, HPEN hpen, int x1, int y1, int x2, int y2)
59+
internal static unsafe 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 void DrawLine(this HDC hdc, HPEN hpen, int x1, int y1, int x2, int y2)
62+
internal static unsafe void DrawLine(this HDC hdc, HPEN hpen, int x1, int y1, int x2, int y2)
6363
{
64-
DrawLines(hdc, hpen, [ x1, y1, x2, y2 ]);
64+
ReadOnlySpan<int> lines = stackalloc int[] { x1, y1, x2, y2 };
65+
DrawLines(hdc, hpen, lines);
6566
}
6667

6768
/// <summary>
@@ -70,7 +71,7 @@ internal static void DrawLine(this HDC hdc, HPEN hpen, int x1, int y1, int x2, i
7071
/// <param name="lines">
7172
/// MUST be a multiple of 4. Each group of 4 represents x1, y1, x2, y2.
7273
/// </param>
73-
internal static void DrawLines(this DeviceContextHdcScope hdc, HPEN hpen, ReadOnlySpan<int> lines)
74+
internal static unsafe void DrawLines(this DeviceContextHdcScope hdc, HPEN hpen, ReadOnlySpan<int> lines)
7475
=> DrawLines(hdc.HDC, hpen, lines);
7576

7677
/// <summary>

src/System.Windows.Forms.Primitives/tests/UnitTests/Interop/Oleaut32/SAFEARRAYTests.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,8 @@ public void SAFEARRAY_GetValue_InvokeSingleDimensional_ReturnsExpected()
220220

221221
try
222222
{
223-
Span<int> indices1 = [0];
224-
Span<int> indices2 = [1];
223+
Span<int> indices1 = stackalloc int[] { 0 };
224+
Span<int> indices2 = stackalloc int[] { 1 };
225225

226226
fixed (int* pIndices1 = indices1)
227227
fixed (int* pIndices2 = indices2)
@@ -266,8 +266,8 @@ public void SAFEARRAY_GetValue_InvokeSingleDimensionalNonZeroLowerBound_ReturnsE
266266

267267
try
268268
{
269-
Span<int> indices1 = [-5];
270-
Span<int> indices2 = [-4];
269+
Span<int> indices1 = stackalloc int[] { -5 };
270+
Span<int> indices2 = stackalloc int[] { -4 };
271271

272272
fixed (int* pIndices1 = indices1)
273273
fixed (int* pIndices2 = indices2)
@@ -318,8 +318,8 @@ public void SAFEARRAY_GetValue_InvokeMultiDimensional_ReturnsExpected()
318318

319319
try
320320
{
321-
Span<int> indices1 = [0, 0];
322-
Span<int> indices2 = [1, 2];
321+
Span<int> indices1 = stackalloc int[] { 0, 0 };
322+
Span<int> indices2 = stackalloc int[] { 1, 2 };
323323

324324
fixed (int* pIndices1 = indices1)
325325
fixed (int* pIndices2 = indices2)
@@ -370,8 +370,8 @@ public void SAFEARRAY_GetValue_InvokeMultiDimensionalNonZeroLowerBound_ReturnsEx
370370

371371
try
372372
{
373-
Span<int> indices1 = [-5, -4];
374-
Span<int> indices2 = [-4, -3];
373+
Span<int> indices1 = stackalloc int[] { -5, -4 };
374+
Span<int> indices2 = stackalloc int[] { -4, -3 };
375375

376376
fixed (int* pIndices1 = indices1)
377377
fixed (int* pIndices2 = indices2)

src/System.Windows.Forms/src/System/Windows/Forms/DateTimePicker.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1327,7 +1327,9 @@ private void SetRange(DateTime min, DateTime max)
13271327
{
13281328
if (IsHandleCreated)
13291329
{
1330-
Span<SYSTEMTIME> times = [(SYSTEMTIME)min, (SYSTEMTIME)max];
1330+
Span<SYSTEMTIME> times = stackalloc SYSTEMTIME[2];
1331+
times[0] = (SYSTEMTIME)min;
1332+
times[1] = (SYSTEMTIME)max;
13311333
uint flags = PInvoke.GDTR_MIN | PInvoke.GDTR_MAX;
13321334
PInvoke.SendMessage(this, PInvoke.DTM_SETRANGE, (WPARAM)(uint)flags, ref times[0]);
13331335
}

src/System.Windows.Forms/src/System/Windows/Forms/GroupBox.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -539,14 +539,14 @@ private void DrawGroupBox(PaintEventArgs e)
539539
{
540540
Color boxColor = Enabled ? ForeColor : SystemColors.GrayText;
541541

542-
ReadOnlySpan<int> lines =
543-
[
542+
ReadOnlySpan<int> lines = stackalloc int[]
543+
{
544544
0, boxTop, 0, Height, // Left
545545
0, Height - 1, Width, Height - 1, // Bottom
546546
0, boxTop, textLeft, boxTop, // Top-left
547547
textRight, boxTop, Width - 1, boxTop, // Top-right
548548
Width - 1, boxTop, Width - 1, Height - 1 // Right
549-
];
549+
};
550550

551551
if (boxColor.HasTransparency())
552552
{
@@ -563,23 +563,23 @@ private void DrawGroupBox(PaintEventArgs e)
563563
}
564564
else
565565
{
566-
ReadOnlySpan<int> lightLines =
567-
[
566+
ReadOnlySpan<int> lightLines = stackalloc int[]
567+
{
568568
1, boxTop, 1, Height - 1, // Left
569569
0, Height - 1, Width, Height - 1, // Bottom
570570
1, boxTop, textLeft, boxTop, // Top-left
571571
textRight, boxTop, Width - 1, boxTop, // Top-right
572572
Width - 1, boxTop - 1, Width - 1, Height - 1 // Right
573-
];
573+
};
574574

575-
ReadOnlySpan<int> darkLines =
576-
[
575+
ReadOnlySpan<int> darkLines = stackalloc int[]
576+
{
577577
0, boxTop, 0, Height - 2, // Left
578578
0, Height - 2, Width - 1, Height - 2, // Bottom
579579
0, boxTop - 1, textLeft, boxTop - 1, // Top-left
580580
textRight, boxTop - 1, Width - 2, boxTop - 1, // Top-right
581581
Width - 2, boxTop - 1, Width - 2, Height - 2 // Right
582-
];
582+
};
583583

584584
using DeviceContextHdcScope hdc = new(e);
585585
using PInvoke.CreatePenScope hpenLight = new(ControlPaint.Light(backColor, 1.0f));

src/System.Windows.Forms/src/System/Windows/Forms/GroupBoxRenderer.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -316,26 +316,26 @@ private static void DrawUnthemedGroupBoxWithText(
316316

317317
using DeviceContextHdcScope hdc = new(deviceContext);
318318

319-
ReadOnlySpan<int> darkLines =
320-
[
319+
ReadOnlySpan<int> darkLines = stackalloc int[]
320+
{
321321
bounds.Left, boxTop - 1, bounds.Left, bounds.Height - 2, // Left
322322
bounds.Left, bounds.Height - 2, bounds.Width - 1, bounds.Height - 2, // Right
323323
bounds.Left, boxTop - 1, textBounds.X - 3, boxTop - 1, // Top-left
324324
textBounds.X + textBounds.Width + 2, boxTop - 1, bounds.Width - 2, boxTop - 1, // Top-right
325325
bounds.Width - 2, boxTop - 1, bounds.Width - 2, bounds.Height - 2 // Right
326-
];
326+
};
327327

328328
using PInvoke.CreatePenScope hpenDark = new(SystemColors.ControlDark);
329329
hdc.DrawLines(hpenDark, darkLines);
330330

331-
ReadOnlySpan<int> lightLines =
332-
[
331+
ReadOnlySpan<int> lightLines = stackalloc int[]
332+
{
333333
bounds.Left + 1, boxTop, bounds.Left + 1, bounds.Height - 1, // Left
334334
bounds.Left, bounds.Height - 1, bounds.Width, bounds.Height - 1, // Right
335335
bounds.Left + 1, boxTop, textBounds.X - 2, boxTop, // Top-left
336336
textBounds.X + textBounds.Width + 1, boxTop, bounds.Width - 1, boxTop, // Top-right
337337
bounds.Width - 1, boxTop, bounds.Width - 1, bounds.Height - 1 // Right
338-
];
338+
};
339339

340340
using PInvoke.CreatePenScope hpenLight = new(SystemColors.ControlLight);
341341
hdc.DrawLines(hpenLight, lightLines);

src/System.Windows.Forms/src/System/Windows/Forms/MonthCalendar.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1826,7 +1826,9 @@ private void SetRange(DateTime minDate, DateTime maxDate)
18261826
// Updated the calendar range
18271827
if (IsHandleCreated)
18281828
{
1829-
Span<SYSTEMTIME> times = [(SYSTEMTIME)minDate, (SYSTEMTIME)maxDate];
1829+
Span<SYSTEMTIME> times = stackalloc SYSTEMTIME[2];
1830+
times[0] = (SYSTEMTIME)minDate;
1831+
times[1] = (SYSTEMTIME)maxDate;
18301832
uint flags = PInvoke.GDTR_MIN | PInvoke.GDTR_MAX;
18311833
if (PInvoke.SendMessage(this, PInvoke.MCM_SETRANGE, (WPARAM)(uint)flags, ref times[0]) == 0)
18321834
{
@@ -1994,7 +1996,9 @@ private void SetSelRange(DateTime lower, DateTime upper)
19941996
// Always set the value on the control, to ensure that it is up to date.
19951997
if (IsHandleCreated)
19961998
{
1997-
Span<SYSTEMTIME> times = [(SYSTEMTIME)lower, (SYSTEMTIME)upper];
1999+
Span<SYSTEMTIME> times = stackalloc SYSTEMTIME[2];
2000+
times[0] = (SYSTEMTIME)lower;
2001+
times[1] = (SYSTEMTIME)upper;
19982002
PInvoke.SendMessage(this, PInvoke.MCM_SETSELRANGE, 0, ref times[0]);
19992003
}
20002004

src/System.Windows.Forms/tests/IntegrationTests/UIIntegrationTests/Input/KeyboardSimulator.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,45 +19,45 @@ public KeyboardSimulator(InputSimulator inputSimulator)
1919

2020
internal KeyboardSimulator KeyDown(VIRTUAL_KEY key)
2121
{
22-
Span<INPUT> inputs =
23-
[
22+
Span<INPUT> inputs = stackalloc INPUT[]
23+
{
2424
InputBuilder.KeyDown(key),
25-
];
25+
};
2626

2727
PInvoke.SendInput(inputs, Marshal.SizeOf<INPUT>());
2828
return this;
2929
}
3030

3131
internal KeyboardSimulator KeyUp(VIRTUAL_KEY key)
3232
{
33-
Span<INPUT> inputs =
34-
[
33+
Span<INPUT> inputs = stackalloc INPUT[]
34+
{
3535
InputBuilder.KeyUp(key),
36-
];
36+
};
3737

3838
PInvoke.SendInput(inputs, Marshal.SizeOf<INPUT>());
3939
return this;
4040
}
4141

4242
internal KeyboardSimulator KeyPress(VIRTUAL_KEY key)
4343
{
44-
Span<INPUT> inputs =
45-
[
44+
Span<INPUT> inputs = stackalloc INPUT[]
45+
{
4646
InputBuilder.KeyDown(key),
4747
InputBuilder.KeyUp(key),
48-
];
48+
};
4949

5050
PInvoke.SendInput(inputs, Marshal.SizeOf<INPUT>());
5151
return this;
5252
}
5353

5454
internal KeyboardSimulator TextEntry(char character)
5555
{
56-
Span<INPUT> inputs =
57-
[
56+
Span<INPUT> inputs = stackalloc INPUT[]
57+
{
5858
InputBuilder.CharacterDown(character),
5959
InputBuilder.CharacterUp(character),
60-
];
60+
};
6161

6262
PInvoke.SendInput(inputs, Marshal.SizeOf<INPUT>());
6363
return this;

src/System.Windows.Forms/tests/IntegrationTests/UIIntegrationTests/Input/MouseSimulator.cs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -80,47 +80,47 @@ internal MouseSimulator RightButtonDoubleClick()
8080

8181
private MouseSimulator ButtonDown(MouseButtons button)
8282
{
83-
Span<INPUT> inputs =
84-
[
83+
Span<INPUT> inputs = stackalloc INPUT[]
84+
{
8585
InputBuilder.MouseButtonDown(button),
86-
];
86+
};
8787

8888
PInvoke.SendInput(inputs, Marshal.SizeOf<INPUT>());
8989
return this;
9090
}
9191

9292
private MouseSimulator ButtonUp(MouseButtons button)
9393
{
94-
Span<INPUT> inputs =
95-
[
94+
Span<INPUT> inputs = stackalloc INPUT[]
95+
{
9696
InputBuilder.MouseButtonUp(button),
97-
];
97+
};
9898

9999
PInvoke.SendInput(inputs, Marshal.SizeOf<INPUT>());
100100
return this;
101101
}
102102

103103
private MouseSimulator ButtonClick(MouseButtons button)
104104
{
105-
Span<INPUT> inputs =
106-
[
105+
Span<INPUT> inputs = stackalloc INPUT[]
106+
{
107107
InputBuilder.MouseButtonDown(button),
108108
InputBuilder.MouseButtonUp(button),
109-
];
109+
};
110110

111111
PInvoke.SendInput(inputs, Marshal.SizeOf<INPUT>());
112112
return this;
113113
}
114114

115115
private MouseSimulator ButtonDoubleClick(MouseButtons button)
116116
{
117-
Span<INPUT> inputs =
118-
[
117+
Span<INPUT> inputs = stackalloc INPUT[]
118+
{
119119
InputBuilder.MouseButtonDown(button),
120120
InputBuilder.MouseButtonUp(button),
121121
InputBuilder.MouseButtonDown(button),
122122
InputBuilder.MouseButtonUp(button),
123-
];
123+
};
124124

125125
PInvoke.SendInput(inputs, Marshal.SizeOf<INPUT>());
126126
return this;
@@ -137,32 +137,32 @@ internal MouseSimulator MoveMouseBy(int x, int y, bool bypassOperatingSystemSett
137137
return MoveMouseTo(virtualPoint.X, virtualPoint.Y);
138138
}
139139

140-
Span<INPUT> inputs =
141-
[
140+
Span<INPUT> inputs = stackalloc INPUT[]
141+
{
142142
InputBuilder.RelativeMouseMovement(x, y),
143-
];
143+
};
144144

145145
PInvoke.SendInput(inputs, Marshal.SizeOf<INPUT>());
146146
return this;
147147
}
148148

149149
internal MouseSimulator MoveMouseTo(double absoluteX, double absoluteY)
150150
{
151-
Span<INPUT> inputs =
152-
[
151+
Span<INPUT> inputs = stackalloc INPUT[]
152+
{
153153
InputBuilder.AbsoluteMouseMovement((int)absoluteX, (int)absoluteY),
154-
];
154+
};
155155

156156
PInvoke.SendInput(inputs, Marshal.SizeOf<INPUT>());
157157
return this;
158158
}
159159

160160
internal MouseSimulator MoveMouseToPositionOnVirtualDesktop(double absoluteX, double absoluteY)
161161
{
162-
Span<INPUT> inputs =
163-
[
162+
Span<INPUT> inputs = stackalloc INPUT[]
163+
{
164164
InputBuilder.AbsoluteMouseMovementOnVirtualDesktop((int)absoluteX, (int)absoluteY),
165-
];
165+
};
166166

167167
PInvoke.SendInput(inputs, Marshal.SizeOf<INPUT>());
168168
return this;

0 commit comments

Comments
 (0)