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
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions idna/src/punycode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@

/// Convert Punycode to an Unicode `String`.
///
/// This is a convenience wrapper around `decode`.
/// Return None on malformed input or overflow.
/// Overflow can only happen on inputs that take more than
/// 63 encoded bytes, the DNS limit on domain name labels.
#[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())

Check warning on line 49 in idna/src/punycode.rs

View check run for this annotation

Codecov / codecov/patch

idna/src/punycode.rs#L49

Added line #L49 was not covered by tests
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

}

/// Convert Punycode to Unicode.
Expand Down
Loading