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 methods to StringBuilder to append ReadOnlySpan<char> #19437

Closed
jamesqo opened this issue Nov 21, 2016 · 4 comments
Closed

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

jamesqo opened this issue Nov 21, 2016 · 4 comments
Labels
api-needs-work API needs work before it is approved, it is NOT ready for implementation area-System.Runtime blocked Issue/PR is blocked on something - see comments
Milestone

Comments

@jamesqo
Copy link
Contributor

jamesqo commented Nov 21, 2016

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

@jkotas
Copy link
Member

jkotas commented Nov 21, 2016

We would need to move Span to System.Runtime contract to make this API work.

Enhancing existing types with Span overloads is in the grand plan, but it is probably too early for it at this point.

@jamesqo
Copy link
Contributor Author

jamesqo commented Nov 21, 2016

@jkotas I see. I'll keep this proposal open for when StringBuilder is able to reference Span, then.

@karelz
Copy link
Member

karelz commented Nov 22, 2016

Wouldn't it be better to track a larger issue with all/most of the APIs extensions we want?
Tracking one offs does not seem to be very effective ...

@karelz
Copy link
Member

karelz commented Nov 22, 2016

Tracking it in general issue (see above) - closing this one

@karelz karelz closed this as completed Nov 22, 2016
@msftgits msftgits transferred this issue from dotnet/corefx Jan 31, 2020
@msftgits msftgits added this to the 2.0.0 milestone Jan 31, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api-needs-work API needs work before it is approved, it is NOT ready for implementation area-System.Runtime blocked Issue/PR is blocked on something - see comments
Projects
None yet
Development

No branches or pull requests

4 participants