-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
[API Proposal]: Add access to StringBuilder content by using ReadOnlySequence<char> #87362
Comments
Tagging subscribers to this area: @dotnet/area-system-memory Issue DetailsBackground and motivationThere are many methods for working with the contents by using the
There are no such methods for the There are 3 ways to deal with the contents of a
I propose to add to the API Proposalnamespace System.Text;
public class StringBuilder: IEnumerable<T>
{
public ReadOnlySequence<char> AsSequence(); // OR GetSequence();
public ReadOnlySequence<char> AsSequence(int startIndex, int length);
}
// OR
public static class StringBuilderExtensions
{
public static ReadOnlySequence<char> AsSequence(this StringBuilder builder);
public static ReadOnlySequence<char> AsSequence(this StringBuilder builder, int startIndex, int length);
} API UsageWherever the
Alternative DesignsRepeating the methods already written for the RisksThe contents of the
|
Tagging subscribers to this area: @dotnet/area-system-runtime Issue DetailsBackground and motivationThere are many methods for working with the contents by using the
There are no such methods for the There are 3 ways to deal with the contents of a
I propose to add to the API Proposalnamespace System.Text;
public class StringBuilder
{
public ReadOnlySequence<char> AsSequence(); // OR GetSequence(); OR ToSequence();
public ReadOnlySequence<char> AsSequence(int startIndex, int length);
}
// OR
public static class StringBuilderExtensions
{
public static ReadOnlySequence<char> AsSequence(this StringBuilder builder);
public static ReadOnlySequence<char> AsSequence(this StringBuilder builder, int startIndex, int length);
} API UsageWherever the
Alternative DesignsRepeating the methods already written for the RisksThe contents of the
|
If we do this on |
Is
|
CoreLib is referenced by everything, and can't reference anything else. It is a single assembly file and doesn't "include" anything. Don't confuse with shared framework. |
If add a new |
I rewrote [API Proposal] based on your comments. Thank you! |
Background and motivation
There are many methods for working with the contents by using the
ReadOnlySequence<char>
structure:There are no such methods for the
StringBuilder
class, and it is often used as a buffer to createstring
content quickly and conveniently. Therefore, there is a desire to work with the contents of theStringBuilder
class as quickly and conveniently as with the contents of theReadOnlySequence<char>
structure.There are 3 ways to deal with the contents of a
StringBuilder
as ways as with theReadOnlySequence<char>
structure:Create a string and use it. This is not optimal.
Use the
StringBuilder.GetChunks()
method and implement the required methods yourself, repeating the methods already written for theReadOnlySequence<char>
structure. This is probably the fastest in terms of code performance, but very costly to implement and test.Convert the
StringBuilder.ChunkEnumerator
structure to aReadOnlySequence<char>
structure and use it further in the already written methods for working with buffers and memory. Implementing such a conversion in third-party libraries will not be the most efficient without access to the internal fields of theStringBuilder
class. This conversion can be done more efficiently by accessing the internal fields of theStringBuilder
class.I propose to add to the
StringBuilder
class (as an option in the extension methods) methods to get its contents as aReadOnlySequence<char>
structure.API Proposal
API Usage
Wherever the
ReadOnlySequence<T>
class is used:Alternative Designs
Repeating the methods already written for the
ReadOnlySequence<char>
structure for theStringBuilder
class.Risks
The contents of the
ReadOnlySequence<char>
structure can be changed by changing the contents of the originalStringBuilder
instance.The text was updated successfully, but these errors were encountered: