]> git.lizzy.rs Git - rust.git/commitdiff
Use String::with_capacity() instead of String::new()
authortopecongiro <seuchida@gmail.com>
Sun, 27 Aug 2017 15:24:10 +0000 (00:24 +0900)
committertopecongiro <seuchida@gmail.com>
Sun, 27 Aug 2017 15:24:10 +0000 (00:24 +0900)
src/items.rs
src/visitor.rs

index 3c4aab69fcc61bbd23b1f2ace895cf43721b3491..6f4fce6a2d70f4667bedd03304570d24225590e6 100644 (file)
@@ -66,7 +66,7 @@ fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
 
         // String that is placed within the assignment pattern and expression.
         let infix = {
-            let mut infix = String::new();
+            let mut infix = String::with_capacity(32);
 
             if let Some(ref ty) = self.ty {
                 let separator = type_annotation_separator(context.config);
@@ -668,7 +668,7 @@ fn format_impl_ref_and_type(
         _,
     ) = item.node
     {
-        let mut result = String::new();
+        let mut result = String::with_capacity(128);
 
         result.push_str(&format_visibility(&item.vis));
         result.push_str(&format_defaultness(defaultness));
@@ -1265,7 +1265,7 @@ pub fn rewrite_type_alias(
     vis: &ast::Visibility,
     span: Span,
 ) -> Option<String> {
-    let mut result = String::new();
+    let mut result = String::with_capacity(128);
 
     result.push_str(&format_visibility(vis));
     result.push_str("type ");
index e6872078365903fd4b776f9ef8aa568b1747e5a9..f07dad4a6ba5e204825cf0dca5d55982b8539da1 100644 (file)
@@ -920,10 +920,10 @@ fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
 
 impl<'a> Rewrite for [ast::Attribute] {
     fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
-        let mut result = String::new();
         if self.is_empty() {
-            return Some(result);
+            return Some(String::new());
         }
+        let mut result = String::with_capacity(128);
         let indent = shape.indent.to_string(context.config);
 
         let mut derive_args = Vec::new();