You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Span extension method to slice off of a string instance #23569
But now I also see a proposal for a non-stack-only StringSegment type. So I have two questions.
Is there a clearly preferable return type for such an extension method?
Is the most efficient way to slice a string str.AsReadOnlySpan().Slice(...), or is there a single method call I can make that I haven't found yet? That's a little verbose for my liking, even if the two calls are inlined.
Is the most efficient way to slice a string str.AsReadOnlySpan().Slice(...), or is there a single method call I can make that I haven't found yet? That's a little verbose for my liking, even if the two calls are inlined.
Yes, that is how you would slice a string. I would imagine you would grab a span from a string once (i.e. call str.AsReadOnlySpan()) and then pass that span around and slice multiple times using span.Slice().
Last time I discussed this with @jaredpar and @MadsTorgersen the conclusion was that we need to be super sure that ReadOnlySpan<char> is the best representation for string slices to take the plunge and bur the best name (Slice) for a method returning ROS<char>.
I think there are two cadidate types for the repserantation: ROS<char> and something like ReadOnlyMemory<char>. The former is safe and fast, but with all the restrictions of ref-like types. The later is subject to tearing, slower, but convinient to use.
There seem to be also similar AsReadOnlySpan() extension for ArraySegment. @KrzysztofCwalina does it make sense to make it consistent with string and array overloads we are adding here?
Activity
karelz commentedon Sep 15, 2017
cc @stephentoub
stephentoub commentedon Sep 15, 2017
cc: @KrzysztofCwalina, @ahsonkhan
Currently, yes.
We've discussed adding such overloads. @KrzysztofCwalina would likely know the current plan.
For now
StringSegmentdoesn't exist. I expect we'll have such discussions as part of considering adding it.ahsonkhan commentedon Sep 15, 2017
Yes, that is how you would slice a string. I would imagine you would grab a span from a string once (i.e. call str.AsReadOnlySpan()) and then pass that span around and slice multiple times using span.Slice().
cc @KrzysztofCwalina
KrzysztofCwalina commentedon Sep 15, 2017
Last time I discussed this with @jaredpar and @MadsTorgersen the conclusion was that we need to be super sure that ReadOnlySpan<char> is the best representation for string slices to take the plunge and bur the best name (Slice) for a method returning ROS<char>.
I think there are two cadidate types for the repserantation: ROS<char> and something like ReadOnlyMemory<char>. The former is safe and fast, but with all the restrictions of ref-like types. The later is subject to tearing, slower, but convinient to use.
KrzysztofCwalina commentedon Nov 28, 2017
We have gotten lots of feedback that the current str.AsReadOnlySpan().Slice(from, length) is to verbose.
Maybe a good compromise would be to add:
@MadsTorgersen, @jaredpar, @stephentoub, @ahsonkhan?
stephentoub commentedon Nov 28, 2017
I'd be fine with such overloads.
KrzysztofCwalina commentedon Nov 28, 2017
@jnm2, could you please update the API design at the top of this issue? ... I will mark it as ready for API review then.
jnm2 commentedon Nov 28, 2017
Oh, forgot this was one I started. 😄 Done.
terrajobst commentedon Dec 5, 2017
Video
That seems like a good suggestion, but we should do the same for arrays.
karelz commentedon Dec 5, 2017
There seem to be also similar
AsReadOnlySpan()extension forArraySegment.@KrzysztofCwalina does it make sense to make it consistent with string and array overloads we are adding here?
karelz commentedon Dec 5, 2017
FYI: The API review discussion was recorded - see https://youtu.be/BI3iXFT8H7E?t=3913 (13 min duration)
Underlying CoreCLR support for new string slicing overloads (#15811)
2 remaining items
Underlying CoreCLR support for new string slicing overloads (#15811)
Underlying CoreCLR support for new string slicing overloads (#15811)
Underlying CoreCLR support for new string slicing overloads (#15811)
Underlying CoreCLR support for new string slicing overloads (#15811)
Small fix to underlying CoreCLR support for new string slicing overlo…
Small fix to underlying CoreCLR support for new string slicing overlo…
Small fix to underlying CoreCLR support for new string slicing overlo…
Small fix to underlying CoreCLR support for new string slicing overlo…
Small fix to underlying CoreCLR support for new string slicing overlo…
Add string slicing extension methods. (#26427)
Underlying CoreCLR support for new string slicing overloads (#15811)