Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reapply params ReadOnlySpan overloads without params keyword #101308

Merged
merged 3 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
201 changes: 172 additions & 29 deletions src/libraries/Common/tests/Tests/System/StringTests.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public static ImmutableArray<T> Create<T>(T item1, T item2, T item3, T item4)
/// <typeparam name="T">The type of element stored in the array.</typeparam>
/// <param name="items">The elements to store in the array.</param>
/// <returns>An immutable array containing the specified items.</returns>
public static ImmutableArray<T> Create<T>(ReadOnlySpan<T> items)
public static ImmutableArray<T> Create<T>(/*params*/ ReadOnlySpan<T> items)
{
if (items.IsEmpty)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ public void AddRange(ImmutableArray<T> items, int length)
/// Adds the specified items to the end of the array.
/// </summary>
/// <param name="items">The items to add at the end of the array.</param>
public void AddRange(ReadOnlySpan<T> items)
public void AddRange(/*params*/ ReadOnlySpan<T> items)
{
int offset = this.Count;
this.Count += items.Length;
Expand All @@ -443,7 +443,7 @@ public void AddRange(ReadOnlySpan<T> items)
/// </summary>
/// <typeparam name="TDerived">The type that derives from the type of item already in the array.</typeparam>
/// <param name="items">The items to add at the end of the array.</param>
public void AddRange<TDerived>(ReadOnlySpan<TDerived> items) where TDerived : T
public void AddRange<TDerived>(/*params*/ ReadOnlySpan<TDerived> items) where TDerived : T
{
int offset = this.Count;
this.Count += items.Length;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,7 @@ public IEnumerable<TResult> OfType<TResult>()
/// </summary>
/// <param name="items">The values to add.</param>
/// <returns>A new list with the elements added.</returns>
public ImmutableArray<T> AddRange(ReadOnlySpan<T> items)
public ImmutableArray<T> AddRange(/*params*/ ReadOnlySpan<T> items)
{
ImmutableArray<T> self = this;
return self.InsertRange(self.Length, items);
Expand Down Expand Up @@ -949,7 +949,7 @@ public ImmutableArray<T> InsertRange(int index, T[] items)
/// <param name="index">The index at which to insert the value.</param>
/// <param name="items">The elements to insert.</param>
/// <returns>The new immutable collection.</returns>
public ImmutableArray<T> InsertRange(int index, ReadOnlySpan<T> items)
public ImmutableArray<T> InsertRange(int index, /*params*/ ReadOnlySpan<T> items)
{
ImmutableArray<T> self = this;
self.ThrowNullRefIfNotInitialized();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public static ImmutableHashSet<T> Create<T>(params T[] items)
/// <typeparam name="T">The type of items stored by the collection.</typeparam>
/// <param name="items">The items to prepopulate.</param>
/// <returns>The new immutable collection.</returns>
public static ImmutableHashSet<T> Create<T>(ReadOnlySpan<T> items)
public static ImmutableHashSet<T> Create<T>(/*params*/ ReadOnlySpan<T> items)
{
return ImmutableHashSet<T>.Empty.Union(items);
}
Expand All @@ -124,7 +124,7 @@ public static ImmutableHashSet<T> Create<T>(IEqualityComparer<T>? equalityCompar
/// <param name="equalityComparer">The equality comparer.</param>
/// <param name="items">The items to prepopulate.</param>
/// <returns>The new immutable collection.</returns>
public static ImmutableHashSet<T> Create<T>(IEqualityComparer<T>? equalityComparer, ReadOnlySpan<T> items)
public static ImmutableHashSet<T> Create<T>(IEqualityComparer<T>? equalityComparer, /*params*/ ReadOnlySpan<T> items)
{
return ImmutableHashSet<T>.Empty.WithComparer(equalityComparer).Union(items);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static ImmutableList<T> Create<T>(params T[] items)
/// <typeparam name="T">The type of items stored by the collection.</typeparam>
/// <param name="items">A span that contains the items to prepopulate the list with.</param>
/// <returns>A new immutable list that contains the specified items.</returns>
public static ImmutableList<T> Create<T>(ReadOnlySpan<T> items) => ImmutableList<T>.Empty.AddRange(items);
public static ImmutableList<T> Create<T>(/*params*/ ReadOnlySpan<T> items) => ImmutableList<T>.Empty.AddRange(items);

/// <summary>
/// Creates a new immutable list builder.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public static ImmutableQueue<T> Create<T>(params T[] items)
/// <typeparam name="T">The type of items in the immutable queue.</typeparam>
/// <param name="items">A span that contains the items to prepopulate the queue with.</param>
/// <returns>A new immutable queue that contains the specified items.</returns>
public static ImmutableQueue<T> Create<T>(ReadOnlySpan<T> items)
public static ImmutableQueue<T> Create<T>(/*params*/ ReadOnlySpan<T> items)
{
if (items.IsEmpty)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public static ImmutableSortedSet<T> Create<T>(params T[] items)
/// <typeparam name="T">The type of items in the immutable set.</typeparam>
/// <param name="items">A span that contains the items to prepopulate the set with.</param>
/// <returns>A new immutable set that contains the specified items.</returns>
public static ImmutableSortedSet<T> Create<T>(ReadOnlySpan<T> items)
public static ImmutableSortedSet<T> Create<T>(/*params*/ ReadOnlySpan<T> items)
{
return ImmutableSortedSet<T>.Empty.Union(items);
}
Expand All @@ -123,7 +123,7 @@ public static ImmutableSortedSet<T> Create<T>(IComparer<T>? comparer, params T[]
/// <param name="comparer">The comparer.</param>
/// <param name="items">The items to prepopulate.</param>
/// <returns>The new immutable collection.</returns>
public static ImmutableSortedSet<T> Create<T>(IComparer<T>? comparer, ReadOnlySpan<T> items)
public static ImmutableSortedSet<T> Create<T>(IComparer<T>? comparer, /*params*/ ReadOnlySpan<T> items)
{
return ImmutableSortedSet<T>.Empty.WithComparer(comparer).Union(items);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public static ImmutableStack<T> Create<T>(params T[] items)
/// <typeparam name="T">The type of items in the immutable stack.</typeparam>
/// <param name="items">A span that contains the items to prepopulate the stack with.</param>
/// <returns>A new immutable stack that contains the specified items.</returns>
public static ImmutableStack<T> Create<T>(ReadOnlySpan<T> items)
public static ImmutableStack<T> Create<T>(/*params*/ ReadOnlySpan<T> items)
{
ImmutableStack<T> stack = ImmutableStack<T>.Empty;
foreach (T item in items)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,15 @@ public void Create()
Assert.Equal(1, set.Count);
Assert.Same(comparer, set.KeyComparer);

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

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ public void Create()
list = ImmutableList.Create("a");
Assert.Equal(1, list.Count);

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

list = ImmutableList.Create((ReadOnlySpan<string>)new[] { "a", "b" });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public void Create()
Assert.False(queue.IsEmpty);
Assert.Equal(new[] { 1 }, queue);

queue = ImmutableQueue.Create(1, 2);
queue = ImmutableQueue.Create(new int[] { 1, 2 });
Assert.False(queue.IsEmpty);
Assert.Equal(new[] { 1, 2 }, queue);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,15 +289,15 @@ public void Create()
Assert.Equal(1, set.Count);
Assert.Same(comparer, set.KeyComparer);

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

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ public void Create()
Assert.False(stack.IsEmpty);
Assert.Equal(new[] { 1 }, stack);

stack = ImmutableStack.Create(1, 2);
stack = ImmutableStack.Create(new[] { 1, 2 });
Assert.False(stack.IsEmpty);
Assert.Equal(new[] { 2, 1 }, stack);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
</ItemGroup>

<ItemGroup>
<Reference Include="System.Memory" />
jozkee marked this conversation as resolved.
Show resolved Hide resolved
<Reference Include="System.Runtime" />
<Reference Include="System.Threading" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

<ItemGroup>
<Reference Include="System.ComponentModel.Primitives" />
<Reference Include="System.Memory" />
<Reference Include="System.Runtime" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<ItemGroup>
<Reference Include="System.ComponentModel" />
<Reference Include="System.ComponentModel.Primitives" />
<Reference Include="System.Memory" />
<Reference Include="System.Runtime" />
<Reference Include="System.Threading" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
<ItemGroup>
<Reference Include="System.Collections.NonGeneric" />
<Reference Include="System.ComponentModel" />
<Reference Include="System.Memory" />
<Reference Include="System.ObjectModel" />
<Reference Include="System.Runtime" />
<Reference Include="System.Threading" />
Expand Down
2 changes: 2 additions & 0 deletions src/libraries/System.Console/ref/System.Console.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ public static void Write([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute(
public static void Write([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("CompositeFormat")] string format, object? arg0, object? arg1) { }
public static void Write([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("CompositeFormat")] string format, object? arg0, object? arg1, object? arg2) { }
public static void Write([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("CompositeFormat")] string format, params object?[]? arg) { }
public static void Write([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("CompositeFormat")] string format, System.ReadOnlySpan<object?> arg) { }
[System.CLSCompliantAttribute(false)]
public static void Write(uint value) { }
[System.CLSCompliantAttribute(false)]
Expand All @@ -195,6 +196,7 @@ public static void WriteLine([System.Diagnostics.CodeAnalysis.StringSyntaxAttrib
public static void WriteLine([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("CompositeFormat")] string format, object? arg0, object? arg1) { }
public static void WriteLine([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("CompositeFormat")] string format, object? arg0, object? arg1, object? arg2) { }
public static void WriteLine([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("CompositeFormat")] string format, params object?[]? arg) { }
public static void WriteLine([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("CompositeFormat")] string format, System.ReadOnlySpan<object?> arg) { }
[System.CLSCompliantAttribute(false)]
public static void WriteLine(uint value) { }
[System.CLSCompliantAttribute(false)]
Expand Down
22 changes: 22 additions & 0 deletions src/libraries/System.Console/src/System/Console.cs
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,17 @@ public static void WriteLine([StringSyntax(StringSyntaxAttribute.CompositeFormat
Out.WriteLine(format, arg);
}

/// <summary>
/// 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.
/// </summary>
/// <param name="format">A composite format string.</param>
/// <param name="arg">A span of objects to write using format.</param>
[MethodImplAttribute(MethodImplOptions.NoInlining)]
public static void WriteLine([StringSyntax(StringSyntaxAttribute.CompositeFormat)] string format, /*params*/ ReadOnlySpan<object?> arg)
{
Out.WriteLine(format, arg);
}

[MethodImplAttribute(MethodImplOptions.NoInlining)]
public static void Write([StringSyntax(StringSyntaxAttribute.CompositeFormat)] string format, object? arg0)
{
Expand Down Expand Up @@ -892,6 +903,17 @@ public static void Write([StringSyntax(StringSyntaxAttribute.CompositeFormat)] s
Out.Write(format, arg);
}

/// <summary>
/// Writes the text representation of the specified span of objects to the standard output stream using the specified format information.
/// </summary>
/// <param name="format">A composite format string.</param>
/// <param name="arg">A span of objects to write using format.</param>
[MethodImplAttribute(MethodImplOptions.NoInlining)]
public static void Write([StringSyntax(StringSyntaxAttribute.CompositeFormat)] string format, /*params*/ ReadOnlySpan<object?> arg)
{
Out.Write(format, arg);
}

[MethodImplAttribute(MethodImplOptions.NoInlining)]
public static void Write(bool value)
{
Expand Down
30 changes: 20 additions & 10 deletions src/libraries/System.Console/tests/ReadAndWrite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,14 @@ private static void WriteCore()
Console.Write("{0}", null, null);
Console.Write("{0} {1} {2}", 32, "Hello", (uint)50);
Console.Write("{0}", null, null, null);
Console.Write("{0} {1} {2} {3}", 32, "Hello", (uint)50, (ulong)5);
Console.Write("{0}", null, null, null, null);
Console.Write("{0} {1} {2} {3} {4}", 32, "Hello", (uint)50, (ulong)5, 'a');
Console.Write("{0}", null, null, null, null, null);
Console.Write("{0} {1} {2} {3}", new object[] { 32, "Hello", (uint)50, (ulong)5 });
Console.Write("{0} {1} {2} {3}", new object[] { 32, "Hello", (uint)50, (ulong)5 }.AsSpan());
Console.Write("{0}", new object[] { null, null, null, null });
Console.Write("{0}", new object[] { null, null, null, null }.AsSpan());
Console.Write("{0} {1} {2} {3} {4}", new object[] { 32, "Hello", (uint)50, (ulong)5, 'a' });
Console.Write("{0} {1} {2} {3} {4}", new object[] { 32, "Hello", (uint)50, (ulong)5, 'a' }.AsSpan());
Console.Write("{0}", new object[] { null, null, null, null, null });
Console.Write("{0}", new object[] { null, null, null, null, null }.AsSpan());
Console.Write(true);
Console.Write('a');
Console.Write(new char[] { 'a', 'b', 'c', 'd', });
Expand Down Expand Up @@ -120,10 +124,14 @@ private static void WriteLineCore()
Console.WriteLine("{0}", null, null);
Console.WriteLine("{0} {1} {2}", 32, "Hello", (uint)50);
Console.WriteLine("{0}", null, null, null);
Console.WriteLine("{0} {1} {2} {3}", 32, "Hello", (uint)50, (ulong)5);
Console.WriteLine("{0}", null, null, null, null);
Console.WriteLine("{0} {1} {2} {3} {4}", 32, "Hello", (uint)50, (ulong)5, 'a');
Console.WriteLine("{0}", null, null, null, null, null);
Console.WriteLine("{0} {1} {2} {3}", new object[] { 32, "Hello", (uint)50, (ulong)5 });
Console.WriteLine("{0} {1} {2} {3}", new object[] { 32, "Hello", (uint)50, (ulong)5 }.AsSpan());
Console.WriteLine("{0}", new object[] { null, null, null, null });
Console.WriteLine("{0}", new object[] { null, null, null, null }.AsSpan());
Console.WriteLine("{0} {1} {2} {3} {4}", new object[] { 32, "Hello", (uint)50, (ulong)5, 'a' });
Console.WriteLine("{0} {1} {2} {3} {4}", new object[] { 32, "Hello", (uint)50, (ulong)5, 'a' }.AsSpan());
Console.WriteLine("{0}", new object[] { null, null, null, null, null });
Console.WriteLine("{0}", new object[] { null, null, null, null, null }.AsSpan());
Console.WriteLine(true);
Console.WriteLine('a');
Console.WriteLine(new char[] { 'a', 'b', 'c', 'd', });
Expand Down Expand Up @@ -158,8 +166,10 @@ public static async Task OutWriteAndWriteLineOverloads()
writer.Write("{0}", 32);
writer.Write("{0} {1}", 32, "Hello");
writer.Write("{0} {1} {2}", 32, "Hello", (uint)50);
writer.Write("{0} {1} {2} {3}", 32, "Hello", (uint)50, (ulong)5);
writer.Write("{0} {1} {2} {3} {4}", 32, "Hello", (uint)50, (ulong)5, 'a');
writer.Write("{0} {1} {2} {3}", new object[] { 32, "Hello", (uint)50, (ulong)5 });
writer.Write("{0} {1} {2} {3}", new object[] { 32, "Hello", (uint)50, (ulong)5 }.AsSpan());
writer.Write("{0} {1} {2} {3} {4}", new object[] { 32, "Hello", (uint)50, (ulong)5, 'a' });
writer.Write("{0} {1} {2} {3} {4}", new object[] { 32, "Hello", (uint)50, (ulong)5, 'a' }.AsSpan());
writer.Write(true);
writer.Write('a');
writer.Write(new char[] { 'a', 'b', 'c', 'd', });
Expand Down
Loading
Loading