Skip to content

Commit 1c824d9

Browse files
authored
Reapply params ReadOnlySpan overloads without params keyword (#101308)
* Reapply "Add params ReadOnlySpan<T> overloads (#100898)" (#101123) This reverts commit 3e569f5. * Comment-out params keyword * Remove /*params*/ from ref
1 parent 7bb7e74 commit 1c824d9

File tree

77 files changed

+1388
-263
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+1388
-263
lines changed

src/libraries/Common/tests/Tests/System/StringTests.cs

Lines changed: 172 additions & 29 deletions
Large diffs are not rendered by default.

src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableArray.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public static ImmutableArray<T> Create<T>(T item1, T item2, T item3, T item4)
8787
/// <typeparam name="T">The type of element stored in the array.</typeparam>
8888
/// <param name="items">The elements to store in the array.</param>
8989
/// <returns>An immutable array containing the specified items.</returns>
90-
public static ImmutableArray<T> Create<T>(ReadOnlySpan<T> items)
90+
public static ImmutableArray<T> Create<T>(/*params*/ ReadOnlySpan<T> items)
9191
{
9292
if (items.IsEmpty)
9393
{

src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableArray_1.Builder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ public void AddRange(ImmutableArray<T> items, int length)
430430
/// Adds the specified items to the end of the array.
431431
/// </summary>
432432
/// <param name="items">The items to add at the end of the array.</param>
433-
public void AddRange(ReadOnlySpan<T> items)
433+
public void AddRange(/*params*/ ReadOnlySpan<T> items)
434434
{
435435
int offset = this.Count;
436436
this.Count += items.Length;
@@ -443,7 +443,7 @@ public void AddRange(ReadOnlySpan<T> items)
443443
/// </summary>
444444
/// <typeparam name="TDerived">The type that derives from the type of item already in the array.</typeparam>
445445
/// <param name="items">The items to add at the end of the array.</param>
446-
public void AddRange<TDerived>(ReadOnlySpan<TDerived> items) where TDerived : T
446+
public void AddRange<TDerived>(/*params*/ ReadOnlySpan<TDerived> items) where TDerived : T
447447
{
448448
int offset = this.Count;
449449
this.Count += items.Length;

src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableArray_1.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,7 @@ public IEnumerable<TResult> OfType<TResult>()
880880
/// </summary>
881881
/// <param name="items">The values to add.</param>
882882
/// <returns>A new list with the elements added.</returns>
883-
public ImmutableArray<T> AddRange(ReadOnlySpan<T> items)
883+
public ImmutableArray<T> AddRange(/*params*/ ReadOnlySpan<T> items)
884884
{
885885
ImmutableArray<T> self = this;
886886
return self.InsertRange(self.Length, items);
@@ -949,7 +949,7 @@ public ImmutableArray<T> InsertRange(int index, T[] items)
949949
/// <param name="index">The index at which to insert the value.</param>
950950
/// <param name="items">The elements to insert.</param>
951951
/// <returns>The new immutable collection.</returns>
952-
public ImmutableArray<T> InsertRange(int index, ReadOnlySpan<T> items)
952+
public ImmutableArray<T> InsertRange(int index, /*params*/ ReadOnlySpan<T> items)
953953
{
954954
ImmutableArray<T> self = this;
955955
self.ThrowNullRefIfNotInitialized();

src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableHashSet.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public static ImmutableHashSet<T> Create<T>(params T[] items)
9898
/// <typeparam name="T">The type of items stored by the collection.</typeparam>
9999
/// <param name="items">The items to prepopulate.</param>
100100
/// <returns>The new immutable collection.</returns>
101-
public static ImmutableHashSet<T> Create<T>(ReadOnlySpan<T> items)
101+
public static ImmutableHashSet<T> Create<T>(/*params*/ ReadOnlySpan<T> items)
102102
{
103103
return ImmutableHashSet<T>.Empty.Union(items);
104104
}
@@ -124,7 +124,7 @@ public static ImmutableHashSet<T> Create<T>(IEqualityComparer<T>? equalityCompar
124124
/// <param name="equalityComparer">The equality comparer.</param>
125125
/// <param name="items">The items to prepopulate.</param>
126126
/// <returns>The new immutable collection.</returns>
127-
public static ImmutableHashSet<T> Create<T>(IEqualityComparer<T>? equalityComparer, ReadOnlySpan<T> items)
127+
public static ImmutableHashSet<T> Create<T>(IEqualityComparer<T>? equalityComparer, /*params*/ ReadOnlySpan<T> items)
128128
{
129129
return ImmutableHashSet<T>.Empty.WithComparer(equalityComparer).Union(items);
130130
}

src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableList.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public static ImmutableList<T> Create<T>(params T[] items)
5252
/// <typeparam name="T">The type of items stored by the collection.</typeparam>
5353
/// <param name="items">A span that contains the items to prepopulate the list with.</param>
5454
/// <returns>A new immutable list that contains the specified items.</returns>
55-
public static ImmutableList<T> Create<T>(ReadOnlySpan<T> items) => ImmutableList<T>.Empty.AddRange(items);
55+
public static ImmutableList<T> Create<T>(/*params*/ ReadOnlySpan<T> items) => ImmutableList<T>.Empty.AddRange(items);
5656

5757
/// <summary>
5858
/// Creates a new immutable list builder.

src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableQueue.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public static ImmutableQueue<T> Create<T>(params T[] items)
8383
/// <typeparam name="T">The type of items in the immutable queue.</typeparam>
8484
/// <param name="items">A span that contains the items to prepopulate the queue with.</param>
8585
/// <returns>A new immutable queue that contains the specified items.</returns>
86-
public static ImmutableQueue<T> Create<T>(ReadOnlySpan<T> items)
86+
public static ImmutableQueue<T> Create<T>(/*params*/ ReadOnlySpan<T> items)
8787
{
8888
if (items.IsEmpty)
8989
{

src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableSortedSet.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public static ImmutableSortedSet<T> Create<T>(params T[] items)
9797
/// <typeparam name="T">The type of items in the immutable set.</typeparam>
9898
/// <param name="items">A span that contains the items to prepopulate the set with.</param>
9999
/// <returns>A new immutable set that contains the specified items.</returns>
100-
public static ImmutableSortedSet<T> Create<T>(ReadOnlySpan<T> items)
100+
public static ImmutableSortedSet<T> Create<T>(/*params*/ ReadOnlySpan<T> items)
101101
{
102102
return ImmutableSortedSet<T>.Empty.Union(items);
103103
}
@@ -123,7 +123,7 @@ public static ImmutableSortedSet<T> Create<T>(IComparer<T>? comparer, params T[]
123123
/// <param name="comparer">The comparer.</param>
124124
/// <param name="items">The items to prepopulate.</param>
125125
/// <returns>The new immutable collection.</returns>
126-
public static ImmutableSortedSet<T> Create<T>(IComparer<T>? comparer, ReadOnlySpan<T> items)
126+
public static ImmutableSortedSet<T> Create<T>(IComparer<T>? comparer, /*params*/ ReadOnlySpan<T> items)
127127
{
128128
return ImmutableSortedSet<T>.Empty.WithComparer(comparer).Union(items);
129129
}

src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableStack.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public static ImmutableStack<T> Create<T>(params T[] items)
7070
/// <typeparam name="T">The type of items in the immutable stack.</typeparam>
7171
/// <param name="items">A span that contains the items to prepopulate the stack with.</param>
7272
/// <returns>A new immutable stack that contains the specified items.</returns>
73-
public static ImmutableStack<T> Create<T>(ReadOnlySpan<T> items)
73+
public static ImmutableStack<T> Create<T>(/*params*/ ReadOnlySpan<T> items)
7474
{
7575
ImmutableStack<T> stack = ImmutableStack<T>.Empty;
7676
foreach (T item in items)

src/libraries/System.Collections.Immutable/tests/ImmutableHashSetTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,15 @@ public void Create()
118118
Assert.Equal(1, set.Count);
119119
Assert.Same(comparer, set.KeyComparer);
120120

121-
set = ImmutableHashSet.Create("a", "b");
121+
set = ImmutableHashSet.Create(new[] { "a", "b" });
122122
Assert.Equal(2, set.Count);
123123
Assert.Same(EqualityComparer<string>.Default, set.KeyComparer);
124124

125125
set = ImmutableHashSet.Create((ReadOnlySpan<string>)new[] { "a", "b" });
126126
Assert.Equal(2, set.Count);
127127
Assert.Same(EqualityComparer<string>.Default, set.KeyComparer);
128128

129-
set = ImmutableHashSet.Create(comparer, "a", "b");
129+
set = ImmutableHashSet.Create(comparer, new[] { "a", "b" });
130130
Assert.Equal(2, set.Count);
131131
Assert.Same(comparer, set.KeyComparer);
132132

src/libraries/System.Collections.Immutable/tests/ImmutableListTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ public void Create()
584584
list = ImmutableList.Create("a");
585585
Assert.Equal(1, list.Count);
586586

587-
list = ImmutableList.Create("a", "b");
587+
list = ImmutableList.Create(new[] { "a", "b" });
588588
Assert.Equal(2, list.Count);
589589

590590
list = ImmutableList.Create((ReadOnlySpan<string>)new[] { "a", "b" });

src/libraries/System.Collections.Immutable/tests/ImmutableQueueTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ public void Create()
213213
Assert.False(queue.IsEmpty);
214214
Assert.Equal(new[] { 1 }, queue);
215215

216-
queue = ImmutableQueue.Create(1, 2);
216+
queue = ImmutableQueue.Create(new int[] { 1, 2 });
217217
Assert.False(queue.IsEmpty);
218218
Assert.Equal(new[] { 1, 2 }, queue);
219219

src/libraries/System.Collections.Immutable/tests/ImmutableSortedSetTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,15 +289,15 @@ public void Create()
289289
Assert.Equal(1, set.Count);
290290
Assert.Same(comparer, set.KeyComparer);
291291

292-
set = ImmutableSortedSet.Create("a", "b");
292+
set = ImmutableSortedSet.Create(new [] { "a", "b" });
293293
Assert.Equal(2, set.Count);
294294
Assert.Same(Comparer<string>.Default, set.KeyComparer);
295295

296296
set = ImmutableSortedSet.Create((ReadOnlySpan<string>)new[] { "a", "b" });
297297
Assert.Equal(2, set.Count);
298298
Assert.Same(Comparer<string>.Default, set.KeyComparer);
299299

300-
set = ImmutableSortedSet.Create(comparer, "a", "b");
300+
set = ImmutableSortedSet.Create(comparer, new[] { "a", "b" });
301301
Assert.Equal(2, set.Count);
302302
Assert.Same(comparer, set.KeyComparer);
303303

src/libraries/System.Collections.Immutable/tests/ImmutableStackTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ public void Create()
241241
Assert.False(stack.IsEmpty);
242242
Assert.Equal(new[] { 1 }, stack);
243243

244-
stack = ImmutableStack.Create(1, 2);
244+
stack = ImmutableStack.Create(new[] { 1, 2 });
245245
Assert.False(stack.IsEmpty);
246246
Assert.Equal(new[] { 2, 1 }, stack);
247247

src/libraries/System.Collections.NonGeneric/src/System.Collections.NonGeneric.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
</ItemGroup>
2222

2323
<ItemGroup>
24+
<Reference Include="System.Memory" />
2425
<Reference Include="System.Runtime" />
2526
<Reference Include="System.Threading" />
2627
</ItemGroup>

src/libraries/System.Collections.Specialized/src/System.Collections.Specialized.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
<ItemGroup>
2525
<Reference Include="System.ComponentModel.Primitives" />
26+
<Reference Include="System.Memory" />
2627
<Reference Include="System.Runtime" />
2728
</ItemGroup>
2829

src/libraries/System.ComponentModel.EventBasedAsync/src/System.ComponentModel.EventBasedAsync.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<ItemGroup>
1919
<Reference Include="System.ComponentModel" />
2020
<Reference Include="System.ComponentModel.Primitives" />
21+
<Reference Include="System.Memory" />
2122
<Reference Include="System.Runtime" />
2223
<Reference Include="System.Threading" />
2324
</ItemGroup>

src/libraries/System.ComponentModel.Primitives/src/System.ComponentModel.Primitives.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
<ItemGroup>
4848
<Reference Include="System.Collections.NonGeneric" />
4949
<Reference Include="System.ComponentModel" />
50+
<Reference Include="System.Memory" />
5051
<Reference Include="System.ObjectModel" />
5152
<Reference Include="System.Runtime" />
5253
<Reference Include="System.Threading" />

src/libraries/System.Console/ref/System.Console.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ public static void Write([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute(
175175
public static void Write([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("CompositeFormat")] string format, object? arg0, object? arg1) { }
176176
public static void Write([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("CompositeFormat")] string format, object? arg0, object? arg1, object? arg2) { }
177177
public static void Write([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("CompositeFormat")] string format, params object?[]? arg) { }
178+
public static void Write([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("CompositeFormat")] string format, System.ReadOnlySpan<object?> arg) { }
178179
[System.CLSCompliantAttribute(false)]
179180
public static void Write(uint value) { }
180181
[System.CLSCompliantAttribute(false)]
@@ -195,6 +196,7 @@ public static void WriteLine([System.Diagnostics.CodeAnalysis.StringSyntaxAttrib
195196
public static void WriteLine([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("CompositeFormat")] string format, object? arg0, object? arg1) { }
196197
public static void WriteLine([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("CompositeFormat")] string format, object? arg0, object? arg1, object? arg2) { }
197198
public static void WriteLine([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("CompositeFormat")] string format, params object?[]? arg) { }
199+
public static void WriteLine([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("CompositeFormat")] string format, System.ReadOnlySpan<object?> arg) { }
198200
[System.CLSCompliantAttribute(false)]
199201
public static void WriteLine(uint value) { }
200202
[System.CLSCompliantAttribute(false)]

src/libraries/System.Console/src/System/Console.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -865,6 +865,17 @@ public static void WriteLine([StringSyntax(StringSyntaxAttribute.CompositeFormat
865865
Out.WriteLine(format, arg);
866866
}
867867

868+
/// <summary>
869+
/// Writes the text representation of the specified span of objects, followed by the current line terminator, to the standard output stream using the specified format information.
870+
/// </summary>
871+
/// <param name="format">A composite format string.</param>
872+
/// <param name="arg">A span of objects to write using format.</param>
873+
[MethodImplAttribute(MethodImplOptions.NoInlining)]
874+
public static void WriteLine([StringSyntax(StringSyntaxAttribute.CompositeFormat)] string format, /*params*/ ReadOnlySpan<object?> arg)
875+
{
876+
Out.WriteLine(format, arg);
877+
}
878+
868879
[MethodImplAttribute(MethodImplOptions.NoInlining)]
869880
public static void Write([StringSyntax(StringSyntaxAttribute.CompositeFormat)] string format, object? arg0)
870881
{
@@ -892,6 +903,17 @@ public static void Write([StringSyntax(StringSyntaxAttribute.CompositeFormat)] s
892903
Out.Write(format, arg);
893904
}
894905

906+
/// <summary>
907+
/// Writes the text representation of the specified span of objects to the standard output stream using the specified format information.
908+
/// </summary>
909+
/// <param name="format">A composite format string.</param>
910+
/// <param name="arg">A span of objects to write using format.</param>
911+
[MethodImplAttribute(MethodImplOptions.NoInlining)]
912+
public static void Write([StringSyntax(StringSyntaxAttribute.CompositeFormat)] string format, /*params*/ ReadOnlySpan<object?> arg)
913+
{
914+
Out.Write(format, arg);
915+
}
916+
895917
[MethodImplAttribute(MethodImplOptions.NoInlining)]
896918
public static void Write(bool value)
897919
{

src/libraries/System.Console/tests/ReadAndWrite.cs

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,14 @@ private static void WriteCore()
8484
Console.Write("{0}", null, null);
8585
Console.Write("{0} {1} {2}", 32, "Hello", (uint)50);
8686
Console.Write("{0}", null, null, null);
87-
Console.Write("{0} {1} {2} {3}", 32, "Hello", (uint)50, (ulong)5);
88-
Console.Write("{0}", null, null, null, null);
89-
Console.Write("{0} {1} {2} {3} {4}", 32, "Hello", (uint)50, (ulong)5, 'a');
90-
Console.Write("{0}", null, null, null, null, null);
87+
Console.Write("{0} {1} {2} {3}", new object[] { 32, "Hello", (uint)50, (ulong)5 });
88+
Console.Write("{0} {1} {2} {3}", new object[] { 32, "Hello", (uint)50, (ulong)5 }.AsSpan());
89+
Console.Write("{0}", new object[] { null, null, null, null });
90+
Console.Write("{0}", new object[] { null, null, null, null }.AsSpan());
91+
Console.Write("{0} {1} {2} {3} {4}", new object[] { 32, "Hello", (uint)50, (ulong)5, 'a' });
92+
Console.Write("{0} {1} {2} {3} {4}", new object[] { 32, "Hello", (uint)50, (ulong)5, 'a' }.AsSpan());
93+
Console.Write("{0}", new object[] { null, null, null, null, null });
94+
Console.Write("{0}", new object[] { null, null, null, null, null }.AsSpan());
9195
Console.Write(true);
9296
Console.Write('a');
9397
Console.Write(new char[] { 'a', 'b', 'c', 'd', });
@@ -120,10 +124,14 @@ private static void WriteLineCore()
120124
Console.WriteLine("{0}", null, null);
121125
Console.WriteLine("{0} {1} {2}", 32, "Hello", (uint)50);
122126
Console.WriteLine("{0}", null, null, null);
123-
Console.WriteLine("{0} {1} {2} {3}", 32, "Hello", (uint)50, (ulong)5);
124-
Console.WriteLine("{0}", null, null, null, null);
125-
Console.WriteLine("{0} {1} {2} {3} {4}", 32, "Hello", (uint)50, (ulong)5, 'a');
126-
Console.WriteLine("{0}", null, null, null, null, null);
127+
Console.WriteLine("{0} {1} {2} {3}", new object[] { 32, "Hello", (uint)50, (ulong)5 });
128+
Console.WriteLine("{0} {1} {2} {3}", new object[] { 32, "Hello", (uint)50, (ulong)5 }.AsSpan());
129+
Console.WriteLine("{0}", new object[] { null, null, null, null });
130+
Console.WriteLine("{0}", new object[] { null, null, null, null }.AsSpan());
131+
Console.WriteLine("{0} {1} {2} {3} {4}", new object[] { 32, "Hello", (uint)50, (ulong)5, 'a' });
132+
Console.WriteLine("{0} {1} {2} {3} {4}", new object[] { 32, "Hello", (uint)50, (ulong)5, 'a' }.AsSpan());
133+
Console.WriteLine("{0}", new object[] { null, null, null, null, null });
134+
Console.WriteLine("{0}", new object[] { null, null, null, null, null }.AsSpan());
127135
Console.WriteLine(true);
128136
Console.WriteLine('a');
129137
Console.WriteLine(new char[] { 'a', 'b', 'c', 'd', });
@@ -158,8 +166,10 @@ public static async Task OutWriteAndWriteLineOverloads()
158166
writer.Write("{0}", 32);
159167
writer.Write("{0} {1}", 32, "Hello");
160168
writer.Write("{0} {1} {2}", 32, "Hello", (uint)50);
161-
writer.Write("{0} {1} {2} {3}", 32, "Hello", (uint)50, (ulong)5);
162-
writer.Write("{0} {1} {2} {3} {4}", 32, "Hello", (uint)50, (ulong)5, 'a');
169+
writer.Write("{0} {1} {2} {3}", new object[] { 32, "Hello", (uint)50, (ulong)5 });
170+
writer.Write("{0} {1} {2} {3}", new object[] { 32, "Hello", (uint)50, (ulong)5 }.AsSpan());
171+
writer.Write("{0} {1} {2} {3} {4}", new object[] { 32, "Hello", (uint)50, (ulong)5, 'a' });
172+
writer.Write("{0} {1} {2} {3} {4}", new object[] { 32, "Hello", (uint)50, (ulong)5, 'a' }.AsSpan());
163173
writer.Write(true);
164174
writer.Write('a');
165175
writer.Write(new char[] { 'a', 'b', 'c', 'd', });

0 commit comments

Comments
 (0)