Skip to content

Conversation

@Joy-less
Copy link
Contributor

This PR does two things:

  1. Simplifies & optimizes Replace(char, char). The built-in logic has low level optimizations on the buffer.
  2. Optimizes ToValueStringBuilder(this StringBuilder) by passing setting the initial capacity to avoid growing the buffer.

They're one PR because I was too lazy to make two.

@Joy-less
Copy link
Contributor Author

Joy-less commented Mar 1, 2025

After benchmarking the optimization, I'm also reintroducing the optimization from my previous PR I closed:

Method Mean Error StdDev Gen0 Allocated
ReplaceChar 31.90 ns 0.189 ns 0.168 ns 0.0255 80 B
ReplaceString 38.85 ns 0.145 ns 0.121 ns 0.0255 80 B

This shows it's a good idea to simply use Replace(char, char) when the spans are of length 1.

Copy link
Owner

@linkdotnet linkdotnet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Give yourself some props in the changelog.

@Joy-less
Copy link
Contributor Author

Joy-less commented Mar 3, 2025

Give yourself some props in the changelog.

Done finally ^-^

@sonarqubecloud
Copy link

sonarqubecloud bot commented Mar 3, 2025

@linkdotnet linkdotnet merged commit e7fa7b9 into linkdotnet:main Mar 3, 2025
3 checks passed
@Joy-less Joy-less deleted the optimize-Replace branch March 3, 2025 21:47
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

Successfully merging this pull request may close these issues.

2 participants