Skip to content
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

Merged
merged 2 commits into from
Jan 10, 2024

Conversation

bishopcheckmate
Copy link
Contributor

Hey,
while indeed decode_to_string is a nice ergonomics addition, the fact of being a wrapper over the decode results in an intermediate Vec.
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

Copy link

codecov bot commented Jan 9, 2024

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (92f356e) 81.70% compared to head (d318128) 81.70%.

❗ Current head d318128 differs from pull request most recent head a5ff8fa. Consider uploading reports for the commit a5ff8fa to get more accurate results

Files Patch % Lines
idna/src/punycode.rs 0.00% 1 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

#[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())
Copy link
Collaborator

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?

Copy link
Contributor Author

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

Copy link
Contributor Author

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

Copy link
Collaborator

@valenting valenting left a comment

Choose a reason for hiding this comment

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

Excellent. Thank you!

@valenting valenting added this pull request to the merge queue Jan 10, 2024
Merged via the queue into servo:master with commit f447500 Jan 10, 2024
12 checks passed
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.

None yet

2 participants