소스 검색

uswitch::uswitch() returning String pre-allocated

uswitch::uswitch now pre-allocates it's capacity to the length of the given String.
Steve Thielemann 1 년 전
부모
커밋
b18351847d
1개의 변경된 파일1개의 추가작업 그리고 1개의 파일을 삭제
  1. 1 1
      src/lib.rs

+ 1 - 1
src/lib.rs

@@ -1,6 +1,6 @@
 
 pub fn uswitch(text: &String) -> String {
-    let mut result: String = String::new();
+    let mut result: String = String::with_capacity(text.len());
     for b in text.bytes() {
         result.push(char::from_u32(b as u32 ^ 'U' as u32).unwrap_or('?'));
     }