Skip to content

Commit 51c1c4c

Browse files
committed
fix benchmarks
1 parent 88b72cf commit 51c1c4c

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/domain.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ pub fn to_unicode(domain: &str) -> Result<String, IdnaError> {
4949
if label.is_empty() {
5050
return Err(IdnaError::EmptyLabel);
5151
}
52-
5352
if !first {
5453
result.push('.');
5554
}
@@ -124,7 +123,8 @@ fn process_label_to_unicode(label: &str) -> Result<String, IdnaError> {
124123
if !validation::is_label_valid(label) {
125124
return Err(IdnaError::ValidationError);
126125
}
127-
return Ok(label.to_string());
126+
// Avoid allocation if possible: return the label as-is if valid
127+
return Ok(label.to_owned());
128128
}
129129

130130
let punycode_part = &label[4..];

src/validation.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ static IS_FORBIDDEN_DOMAIN_CODE_POINT_TABLE: [u8; 256] = [
1313

1414
#[inline]
1515
fn is_forbidden_domain_char(cp: u32) -> bool {
16-
IS_FORBIDDEN_DOMAIN_CODE_POINT_TABLE[cp as usize] != 0
16+
if cp < 256 {
17+
IS_FORBIDDEN_DOMAIN_CODE_POINT_TABLE[cp as usize] != 0
18+
} else {
19+
false
20+
}
1721
}
1822

1923
pub fn valid_name_code_point(cp: u32) -> bool {

0 commit comments

Comments
 (0)