Not sure if it is there already, but Split will be a great addition to Span/Memory, especially those related to char or byte.
Currently, String.Split creates multiple copies of sub-strings in an array. I can remember many times that I ended up rolling my own Split with IndexOf just to avoid creating large number of one-time strings in tight loops.
Adding Split to Span and Memory can alleviate all this, especially in common situations where:
- A
string is split into multiple lines via \n
- Each line is split into multiple fields via white-space to extract a command and parameters
- Each command is processed individually
Both dotnet/corefx#1 and dotnet/corefx#2 above can be replaced by Span.Split which creates a simple array of a value type.
A further enhancement is to have Span.Split return a Span<Span<char>> to avoid creating the array.
Not sure if it is there already, but
Splitwill be a great addition toSpan/Memory, especially those related tocharorbyte.Currently,
String.Splitcreates multiple copies of sub-strings in an array. I can remember many times that I ended up rolling my ownSplitwithIndexOfjust to avoid creating large number of one-time strings in tight loops.Adding
SplittoSpanandMemorycan alleviate all this, especially in common situations where:stringis split into multiple lines via\nBoth dotnet/corefx#1 and dotnet/corefx#2 above can be replaced by
Span.Splitwhich creates a simple array of a value type.A further enhancement is to have
Span.Splitreturn aSpan<Span<char>>to avoid creating the array.