浏览代码

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(?).
Markus Westerlind 8 年之前
父节点
当前提交
3071ad4156
共有 1 个文件被更改,包括 3 次插入2 次删除
  1. 3 2
      idna/src/uts46.rs

+ 3 - 2
idna/src/uts46.rs

@@ -278,11 +278,12 @@ fn validate(label: &str, is_bidi_domain: bool, flags: Flags, errors: &mut Vec<Er
 
 /// http://www.unicode.org/reports/tr46/#Processing
 fn processing(domain: &str, flags: Flags, errors: &mut Vec<Error>) -> String {
-    let mut mapped = String::new();
+    let mut mapped = String::with_capacity(domain.len());
     for c in domain.chars() {
         map_char(c, flags, &mut mapped, errors)
     }
-    let normalized: String = mapped.nfc().collect();
+    let mut normalized = String::with_capacity(mapped.len());
+    normalized.extend(mapped.nfc());
 
     // Find out if it's a Bidi Domain Name
     //