Skip to content

Commit 3071ad4

Browse files
author
Markus Westerlind
committed
perf: Pre-allocate the strings in processing (-5%)
This might not be exact, but it should be a good estimate. I don't think this will ever over allocate in any case(?).
1 parent e035f89 commit 3071ad4

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

idna/src/uts46.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,11 +278,12 @@ fn validate(label: &str, is_bidi_domain: bool, flags: Flags, errors: &mut Vec<Er
278278

279279
/// http://www.unicode.org/reports/tr46/#Processing
280280
fn processing(domain: &str, flags: Flags, errors: &mut Vec<Error>) -> String {
281-
let mut mapped = String::new();
281+
let mut mapped = String::with_capacity(domain.len());
282282
for c in domain.chars() {
283283
map_char(c, flags, &mut mapped, errors)
284284
}
285-
let normalized: String = mapped.nfc().collect();
285+
let mut normalized = String::with_capacity(mapped.len());
286+
normalized.extend(mapped.nfc());
286287

287288
// Find out if it's a Bidi Domain Name
288289
//

0 commit comments

Comments
 (0)