refactor: remove unnecessary allocations in error formatting#79
Merged
tisonkun merged 2 commits intoapache:mainfrom Jan 29, 2026
Merged
refactor: remove unnecessary allocations in error formatting#79tisonkun merged 2 commits intoapache:mainfrom
tisonkun merged 2 commits intoapache:mainfrom
Conversation
The previous implementation allocated a temporary Vector and multiple Strings just to format the context map. This commit switches to a streaming approach using `write!`, which writes directly to the formatter without heap allocations. No functional changes. Signed-off-by: Cheng-Yang Chou <yphbchou0911@gmail.com>
tisonkun
approved these changes
Jan 29, 2026
Member
tisonkun
left a comment
There was a problem hiding this comment.
Look reasonable. Would you add a test to guard the output stay the same?
That is, add a (snapshot) test assert the output format (error with context) so that further refactoring can be easilier reviewed.
Introduces unit tests to verify the correctness of the `Display` implementation for the `Error` struct. The new tests cover: 1. Basic error messages without context. 2. Complex messages with multiple context items. Suggested-by: @tisonkun Signed-off-by: Cheng-Yang Chou <yphbchou0911@gmail.com>
auto-merge was automatically disabled
January 29, 2026 02:37
Head branch was pushed to by a user without write access
c54f58a to
7d63c1d
Compare
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The previous implementation allocated a temporary Vector and multiple Strings just to format the context map. This commit switches to a streaming approach using
write!, which writes directly to the formatter without heap allocations.No functional changes.
@tisonkun PTAL, thanks.