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

Code before:
                return Task.Factory.StartNew(static state =>
                {
                    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>
        /// 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)
            {
                return Task.CompletedTask;
            }

            return WriteAsync(buffer, 0, buffer.Length);
        }

        public virtual Task WriteAsync(char[] buffer, int index, int count) =>

Review comment (suggestion):
@bartonjs, was there any discussion in API review about instead adding an implicit operator from string to `ReadOnlyMemory<char>` (just as it has one to span)? Two of the three overloads being added here would then seem unnecessary.

Code after:
                return Task.Factory.StartNew(static state =>
                {
                    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)
        {