]> git.lizzy.rs Git - rust.git/commitdiff
Change `to_string` to `to_owned` when it just creates a `String` from a `&str`
authorTobias Bucher <tobiasbucher5991@gmail.com>
Thu, 30 Apr 2015 08:31:42 +0000 (10:31 +0200)
committerTobias Bucher <tobiasbucher5991@gmail.com>
Thu, 30 Apr 2015 08:31:42 +0000 (10:31 +0200)
This means that it doesn't have to go through the formatting hierarchy and can
just immediately reserve enough memory.

src/changes.rs
src/functions.rs
src/imports.rs
src/mod.rs
src/visitor.rs

index 2b42c16469006561f553e5009214a2968109a927..8884b05d77ea49e94b084fddedfcdb0fe4647e34 100644 (file)
@@ -153,8 +153,8 @@ pub fn write_file(&self,
                 // Do a little dance to make writing safer - write to a temp file
                 // rename the original to a .bk, then rename the temp file to the
                 // original.
-                let tmp_name = filename.to_string() + ".tmp";
-                let bk_name = filename.to_string() + ".bk";
+                let tmp_name = filename.to_owned() + ".tmp";
+                let bk_name = filename.to_owned() + ".bk";
                 {
                     // Write text to temp file
                     let mut tmp_file = try!(File::create(&tmp_name));
@@ -165,7 +165,7 @@ pub fn write_file(&self,
                 try!(::std::fs::rename(tmp_name, filename));
             }
             WriteMode::NewFile(extn) => {
-                let filename = filename.to_string() + "." + extn;
+                let filename = filename.to_owned() + "." + extn;
                 let mut file = try!(File::create(&filename));
                 try!(write!(file, "{}", text));
             }
index a753f38d9f792a118ae9aad5acc16f49d7a836a4..3d6fcb88c25462ae52017e45fc5390b61ba6ed50 100644 (file)
@@ -154,7 +154,7 @@ fn rewrite_args(&self,
                         &None => String::new(),
                     };
                     let mut_str = match m {
-                        &ast::Mutability::MutMutable => "mut ".to_string(),
+                        &ast::Mutability::MutMutable => "mut ".to_owned(),
                         &ast::Mutability::MutImmutable => String::new(),
                     };
                     arg_item_strs[0] = format!("&{}{}self", lt_str, mut_str);
@@ -164,7 +164,7 @@ fn rewrite_args(&self,
                     arg_item_strs[0] = format!("self: {}", pprust::ty_to_string(ty));
                 }
                 ast::ExplicitSelf_::SelfValue(_) => {
-                    arg_item_strs[0] = "self".to_string();
+                    arg_item_strs[0] = "self".to_owned();
                     min_args = 2;
                 }
                 _ => {}
@@ -174,7 +174,7 @@ fn rewrite_args(&self,
         // Comments between args
         let mut arg_comments = Vec::new();
         if min_args == 2 {
-            arg_comments.push("".to_string());
+            arg_comments.push("".to_owned());
         }
         // TODO if there are no args, there might still be a comment, but without
         // spans for the comment or parens, there is no chance of getting it right.
@@ -239,7 +239,7 @@ fn make_comments_for_list<T, I, F1, F2>(&self,
             } else if snippet.ends_with(separator) {
                 snippet = snippet[..snippet.len()-separator.len()].trim_matches(white_space);
             }
-            result.push(snippet.to_string());
+            result.push(snippet.to_owned());
             prev_end = get_hi(&item);
         }
         // Get the last commment.
@@ -254,7 +254,7 @@ fn make_comments_for_list<T, I, F1, F2>(&self,
         let snippet = &snippet[..snippet.find(terminator)
                                     .unwrap_or(snippet.find(separator).unwrap_or(snippet.len()))];
         let snippet = snippet.trim();
-        result.push(snippet.to_string());
+        result.push(snippet.to_owned());
 
         result
     }
@@ -422,8 +422,8 @@ fn rewrite_where_clause(&self,
     fn rewrite_return(&self, ret: &ast::FunctionRetTy) -> String {
         match *ret {
             ast::FunctionRetTy::DefaultReturn(_) => String::new(),
-            ast::FunctionRetTy::NoReturn(_) => "-> !".to_string(),
-            ast::FunctionRetTy::Return(ref ty) => "-> ".to_string() + &pprust::ty_to_string(ty),
+            ast::FunctionRetTy::NoReturn(_) => "-> !".to_owned(),
+            ast::FunctionRetTy::Return(ref ty) => "-> ".to_owned() + &pprust::ty_to_string(ty),
         }
     }
 
index 1532050522a2053591b7f410c6ca04518f6e4a63..09a702dbaa1b09c9e0a51483dd26b4e6c87ead51 100644 (file)
@@ -70,7 +70,7 @@ pub fn rewrite_use_list(&mut self,
                 false
             }
         ) {
-            Some(("self".to_string(), String::new()))
+            Some(("self".to_owned(), String::new()))
         } else {
             None
         };
index be0bea4b70cac275891fc689a3decc4b4c6c9f45..45b2bce1638adc38181e7c3d251eeb4c52620fdb 100644 (file)
@@ -305,12 +305,12 @@ fn idempotent_tests() {
             let path = entry.unwrap().path();
             let file_name = path.to_str().unwrap();
             println!("Testing '{}'...", file_name);
-            run(vec!["rustfmt".to_string(), file_name.to_string()], WriteMode::Return(HANDLE_RESULT));
+            run(vec!["rustfmt".to_owned(), file_name.to_owned()], WriteMode::Return(HANDLE_RESULT));
             count += 1;
         }
         // And also dogfood ourselves!
         println!("Testing 'src/mod.rs'...");
-        run(vec!["rustfmt".to_string(), "src/mod.rs".to_string()], WriteMode::Return(HANDLE_RESULT));
+        run(vec!["rustfmt".to_owned(), "src/mod.rs".to_owned()], WriteMode::Return(HANDLE_RESULT));
         count += 1;
 
         // Display results
index 75dcdb12601d3abbf732417b0130f569f43bb06b..7a9c8583039b0f141fbbc6a048106420af3e76c0 100644 (file)
@@ -223,7 +223,7 @@ pub fn snippet(&self, span: Span) -> String {
                 println!("Couldn't make snippet for span {:?}->{:?}",
                          self.codemap.lookup_char_pos(span.lo),
                          self.codemap.lookup_char_pos(span.hi));
-                "".to_string()
+                "".to_owned()
             }
         }
     }