Procházet zdrojové kódy

uswitch::uswitch() returning String pre-allocated

uswitch::uswitch now pre-allocates it's capacity to the length of the given String.
Steve Thielemann před 1 rokem
rodič
revize
b18351847d
1 změnil soubory, kde provedl 1 přidání a 1 odebrání
  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('?'));
     }