-
Notifications
You must be signed in to change notification settings - Fork 308
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
perf(punycode): avoid double allocation in decode_to_string #894
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## master #894 +/- ##
=======================================
Coverage 81.70% 81.70%
=======================================
Files 20 20
Lines 3547 3547
=======================================
Hits 2898 2898
Misses 649 649 ☔ View full report in Codecov by Sentry. |
#[inline] | ||
pub fn decode_to_string(input: &str) -> Option<String> { | ||
decode(input).map(|chars| chars.into_iter().collect()) | ||
Some(Decoder::default().decode(input).ok()?.collect()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you maybe add a unit test that exercises this method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure, will do that at the evening
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is now being tested together with encode_str and decode
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent. Thank you!
Hey,
while indeed
decode_to_string
is a nice ergonomics addition, the fact of being a wrapper over thedecode
results in an intermediateVec
.Since the implementation of it can be the same as
decode
and it's quite straightforward, maybe we could get rid of double alloc cheaply