perf: Add a zero-allocation version of the API #11
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a follow-up to PR #8
This PR renames
Utf8String
toChars
, makes it (mostly) public, and adds the following new zero-allocation APIs:Unfortunately, since generic value tuples cannot carry
Chars
, one cannot simply return(Chars, Chars)
or(Chars Adjective, Chars Noun)
so out parameters are used instead. The other way to solve this would be to introduce aCharsPair
type, but that would just add more code to maintain and test, and bring marginal benefits (though it can always be done later too).Utf8String
is renamed toChars
to encapsulate how data is stored internally. It has methods that permit writing intochar
and UTF-8byte
buffers for those who care to avoid an allocation; for those who don't care can simply callToString()
.The benchmarks are updated and show roughly a 5x performance increase and zero allocations with the new members: