Repository: dotnet/runtime
File: src/libraries/System.Private.CoreLib/src/System/IO/TextWriter.cs (C#)

Code before:
                {
                    var t = (TupleSlim<TextWriter, char, char>)state!;
                    t.Item1.Write(t.Item2);
                    t.Item1.Write(t.Item3);
                }, new TupleSlim<TextWriter, char, char>(this, valueChars[0], valueChars[1]), CancellationToken.None, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);
            }

            return WriteAsync(valueChars[0]);
        }

        public virtual Task WriteAsync(string? value) =>
            Task.Factory.StartNew(static state =>
            {
                var t = (TupleSlim<TextWriter, string?>)state!;
                t.Item1.Write(t.Item2);
            }, new TupleSlim<TextWriter, string?>(this, value), CancellationToken.None, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);

        /// <summary>
        /// Writes a string to the text stream asynchronously.
        /// </summary>
        /// <param name="value">The string to write. If <paramref name="value"/> is <see langword="null"/>, nothing is written.</param>
        /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
        /// <returns>A task that represents the asynchronous write operation.</returns>
        public Task WriteAsync(string? value, CancellationToken cancellationToken) =>
            cancellationToken.IsCancellationRequested ? Task.FromCanceled(cancellationToken) :
            value == null ? Task.CompletedTask :
            WriteAsync(value.AsMemory(), cancellationToken);

        /// <summary>
        /// Equivalent to WriteAsync(stringBuilder.ToString()) however it uses the
        /// StringBuilder.GetChunks() method to avoid creating the intermediate string
        /// </summary>
        /// <param name="value">The string (as a StringBuilder) to write to the stream</param>
        /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
        public virtual Task WriteAsync(StringBuilder? value, CancellationToken cancellationToken = default)
        {
            return
                cancellationToken.IsCancellationRequested ? Task.FromCanceled(cancellationToken) :
                value == null ? Task.CompletedTask :
                WriteAsyncCore(value, cancellationToken);

            async Task WriteAsyncCore(StringBuilder sb, CancellationToken ct)
            {
                foreach (ReadOnlyMemory<char> chunk in sb.GetChunks())
                {
                    await WriteAsync(chunk, ct).ConfigureAwait(false);
                }
            }
        }

        public Task WriteAsync(char[]? buffer)

Review comment (suggestion):
@copilot, these two lines should be removed, such that it just always delegates to the memory overload.

Code after:
                {
                    var t = (TupleSlim<TextWriter, char, char>)state!;
                    t.Item1.Write(t.Item2);
                    t.Item1.Write(t.Item3);
                }, new TupleSlim<TextWriter, char, char>(this, valueChars[0], valueChars[1]), CancellationToken.None, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);
            }

            return WriteAsync(valueChars[0]);
        }

        public virtual Task WriteAsync(string? value) =>
            Task.Factory.StartNew(static state =>
            {
                var t = (TupleSlim<TextWriter, string?>)state!;
                t.Item1.Write(t.Item2);
            }, new TupleSlim<TextWriter, string?>(this, value), CancellationToken.None, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);

        /// <summary>
        /// Writes a string to the text stream asynchronously.
        /// </summary>
        /// <param name="value">The string to write. If <paramref name="value"/> is <see langword="null"/>, nothing is written.</param>
        /// <param name="cancellationToken">The token to monitor for cancellation requests. The default value is <see cref="CancellationToken.None"/>.</param>
        /// <returns>A task that represents the asynchronous write operation.</returns>
        public Task WriteAsync(string? value, CancellationToken cancellationToken) =>
            WriteAsync(value.AsMemory(), cancellationToken);

        /// <summary>
        /// Equivalent to WriteAsync(stringBuilder.ToString()) however it uses the
        /// StringBuilder.GetChunks() method to avoid creating the intermediate string
        /// </summary>
        /// <param name="value">The string (as a StringBuilder) to write to the stream</param>
        /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
        public virtual Task WriteAsync(StringBuilder? value, CancellationToken cancellationToken = default)
        {
            return
                cancellationToken.IsCancellationRequested ? Task.FromCanceled(cancellationToken) :
                value == null ? Task.CompletedTask :
                WriteAsyncCore(value, cancellationToken);

            async Task WriteAsyncCore(StringBuilder sb, CancellationToken ct)
            {
                foreach (ReadOnlyMemory<char> chunk in sb.GetChunks())
                {
                    await WriteAsync(chunk, ct).ConfigureAwait(false);
                }
            }
        }

        public Task WriteAsync(char[]? buffer)
        {
            if (buffer == null)