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

Add Console.Write{Line} span overloads #105531

Merged
merged 1 commit into from
Aug 15, 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
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 @@ -171,6 +171,7 @@ public static void Write(long value) { }
public static void Write(object? value) { }
public static void Write(float value) { }
public static void Write(string? value) { }
public static void Write(System.ReadOnlySpan<char> value) { }
public static void Write([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("CompositeFormat")] string format, object? arg0) { }
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) { }
Expand All @@ -192,6 +193,7 @@ public static void WriteLine(long value) { }
public static void WriteLine(object? value) { }
public static void WriteLine(float value) { }
public static void WriteLine(string? value) { }
public static void WriteLine(ReadOnlySpan<char> value) { }
public static void WriteLine([System.Diagnostics.CodeAnalysis.StringSyntaxAttribute("CompositeFormat")] string format, object? arg0) { }
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) { }
Expand Down
12 changes: 12 additions & 0 deletions src/libraries/System.Console/src/System/Console.cs
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,12 @@ public static void WriteLine(string? value)
Out.WriteLine(value);
}

[MethodImplAttribute(MethodImplOptions.NoInlining)]
public static void WriteLine(ReadOnlySpan<char> value)
{
Out.WriteLine(value);
}

[MethodImplAttribute(MethodImplOptions.NoInlining)]
public static void WriteLine([StringSyntax(StringSyntaxAttribute.CompositeFormat)] string format, object? arg0)
{
Expand Down Expand Up @@ -994,6 +1000,12 @@ public static void Write(string? value)
Out.Write(value);
}

[MethodImplAttribute(MethodImplOptions.NoInlining)]
public static void Write(ReadOnlySpan<char> value)
{
Out.Write(value);
}

private static void HandlePosixSignal(PosixSignalContext ctx)
{
Debug.Assert(ctx.Signal == PosixSignal.SIGINT || ctx.Signal == PosixSignal.SIGQUIT);
Expand Down
3 changes: 3 additions & 0 deletions src/libraries/System.Console/tests/ReadAndWrite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ private static void WriteCore()
Console.Write(50UL);
Console.Write(new object());
Console.Write("Hello World");
Console.Write("Hello World".AsSpan());
}

private static void WriteLineCore()
Expand Down Expand Up @@ -145,6 +146,7 @@ private static void WriteLineCore()
Console.WriteLine(50UL);
Console.WriteLine(new object());
Console.WriteLine("Hello World");
Console.WriteLine("Hello World".AsSpan());
}

[Fact]
Expand Down Expand Up @@ -187,6 +189,7 @@ public static async Task OutWriteAndWriteLineOverloads()
writer.Write(50UL);
writer.Write(new object());
writer.Write("Hello World");
writer.Write("Hello World".AsSpan());

writer.Flush();

Expand Down
Loading