Skip to content

Add methods to StringBuilder to append ReadOnlySpan<char> #19437

@jamesqo

Description

@jamesqo

Background

It seems logical that we should support appending Span<char> and ReadOnlySpan<char> to a StringBuilder, since the point of both data types is to reduce allocations. The only way to do this with the current APIs is to loop through the span one char at a time and call Append on each of them, which is pretty slow.

Proposed API

namespace System.Text
{
    public sealed class StringBuilder
    {
        // Span is implicitly convertible to ReadOnlySpan
        public StringBuilder Append(ReadOnlySpan<char> value);
    }
}

cc @jkotas, @KrzysztofCwalina, @justinvp

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-needs-workAPI needs work before it is approved, it is NOT ready for implementationarea-System.RuntimeblockedIssue/PR is blocked on something - see comments

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions