Skip to content

Commit

Permalink
perf(punycode): avoid double allocation in decode_to_string
Browse files Browse the repository at this point in the history
  • Loading branch information
bishopcheckmate committed Jan 8, 2024
1 parent 92f356e commit d318128
Showing 1 changed file with 4 additions and 2 deletions.
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 @@ fn adapt(mut delta: u32, num_points: u32, first_time: bool) -> u32 {

/// 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
}

/// Convert Punycode to Unicode.
Expand Down

0 comments on commit d318128

Please sign in to comment.