Skip to content
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

Can u change your current stringbuilder.tostring to ------> (see in the description box) #35

Closed
CodingMadness opened this issue Nov 10, 2020 · 1 comment

Comments

@CodingMadness
Copy link

CodingMadness commented Nov 10, 2020

public override string ToString()
      {
         return string.Create(buffer.Length, buffer,
            (x, y) =>
            {
               y.AsSpan(0, x.Length).CopyTo(x);
            }
         );
      }

i have read several times that the new string.Create(..) is much faster since it does only 1 internal allocation when u know the exact size of the buffer u wanna create a string of, and you do ! and there are ofc also no extra delegate allocation in this when u avouid using the 2.parameter "state" and use the (x, y) only! which I do in this case.

@neuecc
Copy link
Member

neuecc commented Jan 14, 2021

This is faster for APIs that need to write to Span.
In the case of ZString, the result will be the same since there is a written Buffer.

@neuecc neuecc closed this as completed Jan 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants