about summary refs log tree commit diff
path: root/src/libsyntax_ext
diff options
context:
space:
mode:
Diffstat (limited to 'src/libsyntax_ext')
-rw-r--r--src/libsyntax_ext/deriving/decodable.rs4
-rw-r--r--src/libsyntax_ext/deriving/generic/mod.rs17
-rw-r--r--src/libsyntax_ext/deriving/hash.rs5
-rw-r--r--src/libsyntax_ext/format.rs15
4 files changed, 19 insertions, 22 deletions
diff --git a/src/libsyntax_ext/deriving/decodable.rs b/src/libsyntax_ext/deriving/decodable.rs
index 1e04d8fa22a..c2b92944999 100644
--- a/src/libsyntax_ext/deriving/decodable.rs
+++ b/src/libsyntax_ext/deriving/decodable.rs
@@ -131,8 +131,8 @@ fn decodable_substructure(cx: &mut ExtCtxt,
         StaticEnum(_, ref fields) => {
             let variant = cx.ident_of("i");
 
-            let mut arms = Vec::new();
-            let mut variants = Vec::new();
+            let mut arms = Vec::with_capacity(fields.len() + 1);
+            let mut variants = Vec::with_capacity(fields.len());
             let rvariant_arg = cx.ident_of("read_enum_variant_arg");
 
             for (i, &(ident, v_span, ref parts)) in fields.iter().enumerate() {
diff --git a/src/libsyntax_ext/deriving/generic/mod.rs b/src/libsyntax_ext/deriving/generic/mod.rs
index a9f60fd053c..e0f985c26c7 100644
--- a/src/libsyntax_ext/deriving/generic/mod.rs
+++ b/src/libsyntax_ext/deriving/generic/mod.rs
@@ -188,6 +188,7 @@ pub use self::StaticFields::*;
 pub use self::SubstructureFields::*;
 
 use std::cell::RefCell;
+use std::iter;
 use std::vec;
 
 use rustc_target::spec::abi::Abi;
@@ -558,15 +559,13 @@ impl<'a> TraitDef<'a> {
                     // type being derived upon
                     self.additional_bounds.iter().map(|p| {
                         cx.trait_bound(p.to_path(cx, self.span, type_ident, generics))
-                    }).collect();
-
-                // require the current trait
-                bounds.push(cx.trait_bound(trait_path.clone()));
-
-                // also add in any bounds from the declaration
-                for declared_bound in &param.bounds {
-                    bounds.push((*declared_bound).clone());
-                }
+                    }).chain(
+                        // require the current trait
+                        iter::once(cx.trait_bound(trait_path.clone()))
+                    ).chain(
+                        // also add in any bounds from the declaration
+                        param.bounds.iter().cloned()
+                    ).collect();
 
                 cx.typaram(self.span, param.ident, vec![], bounds, None)
             }
diff --git a/src/libsyntax_ext/deriving/hash.rs b/src/libsyntax_ext/deriving/hash.rs
index 7d22998487b..950e8c84f17 100644
--- a/src/libsyntax_ext/deriving/hash.rs
+++ b/src/libsyntax_ext/deriving/hash.rs
@@ -95,9 +95,8 @@ fn hash_substructure(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure)
         _ => cx.span_bug(trait_span, "impossible substructure in `derive(Hash)`"),
     };
 
-    for &FieldInfo { ref self_, span, .. } in fields {
-        stmts.push(call_hash(span, self_.clone()));
-    }
+    stmts.extend(fields.iter().map(|FieldInfo { ref self_, span, .. }|
+        call_hash(*span, self_.clone())));
 
     cx.expr_block(cx.block(trait_span, stmts))
 }
diff --git a/src/libsyntax_ext/format.rs b/src/libsyntax_ext/format.rs
index 98de3d80b1e..46c85497ee7 100644
--- a/src/libsyntax_ext/format.rs
+++ b/src/libsyntax_ext/format.rs
@@ -406,10 +406,7 @@ impl<'a, 'b> Context<'a, 'b> {
         // Map the arguments
         for i in 0..args_len {
             let ref arg_types = self.arg_types[i];
-            let mut arg_offsets = Vec::with_capacity(arg_types.len());
-            for offset in arg_types {
-                arg_offsets.push(sofar + *offset);
-            }
+            let arg_offsets = arg_types.iter().map(|offset| sofar + *offset).collect::<Vec<_>>();
             self.arg_index_map.push(arg_offsets);
             sofar += self.arg_unique_types[i].len();
         }
@@ -581,10 +578,12 @@ impl<'a, 'b> Context<'a, 'b> {
     /// Actually builds the expression which the format_args! block will be
     /// expanded to
     fn into_expr(self) -> P<ast::Expr> {
-        let mut locals = Vec::new();
-        let mut counts = Vec::new();
-        let mut pats = Vec::new();
-        let mut heads = Vec::new();
+        let mut locals = Vec::with_capacity(
+            (0..self.args.len()).map(|i| self.arg_unique_types[i].len()).sum()
+        );
+        let mut counts = Vec::with_capacity(self.count_args.len());
+        let mut pats = Vec::with_capacity(self.args.len());
+        let mut heads = Vec::with_capacity(self.args.len());
 
         let names_pos: Vec<_> = (0..self.args.len())
             .map(|i| self.ecx.ident_of(&format!("arg{}", i)).gensym())