Skip to content

Proposal: Span/Memory.Split #27667

@schungx

Description

@schungx

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:

  1. A string is split into multiple lines via \n
  2. Each line is split into multiple fields via white-space to extract a command and parameters
  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions