fix: Optimize dynamic string building #491
Merged
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 reduces intermediate allocations, especially when dynamically building a label.
One could imagine taking advantage of this in a self-voicing adapter to write the label, value, or text range directly into the buffer that contains the utterance to be spoken, and that buffer could be reused across utterances.
On Windows, this allows us to construct the dynamic string as UTF-16 in one pass, rather than constructing it as UTF-8 and then re-encoding it to UTF-16 in another pass, adding a temporary allocation.
This change happens to add 512 bytes to the binary size of a
panic_immediate_abort
build of the Windowshello_world
example on x86-64. It doesn't have any effect on the binary size of that same example built as a normal release build withpanic = "abort"
.