-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Closed
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-System.Runtime
Milestone
Description
Background and motivation
I am operating a lot with spans and slicees and I would super like to not get forced to write-out the span to a string by "builder.ToString()", if possible.
It would save tremendous allocations cause when working in game dev /graphics related stuff , the amount of calls which happen per second make up a significant GC-pressure, so would be nice to avoid that.
API Proposal
public StringBuilder Replace(ReadOnlySpan<char> oldValue, ReadOnlySpan<char> newValue, int startIndex, int count)
public StringBuilder Replace(ReadOnlySpan<char> oldValue, ReadOnlySpan<char> newValue)API Usage
string input = "Hello world";
ROS charSpan = bigString.Slice(0, 5);
ROS replacer = stackalloc char[] {'d', 'e', 'a', 'r'};
StringBuilder builder = new(input);
builder.Replace(charSpan, replacer);
var output = builder.ToString(); // --> dear worldAlternative Designs
Due to backward compatibility, it would be only an option to add a new API.
Risks
AFAIK none.
NN---, startewho and CodingMadness
Metadata
Metadata
Assignees
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-System.Runtime