diff options
| author | ljedrz <ljedrz@gmail.com> | 2018-07-26 17:11:10 +0200 |
|---|---|---|
| committer | ljedrz <ljedrz@gmail.com> | 2018-07-29 18:53:22 +0200 |
| commit | 59c8a279daf6912b99ba089ff6dafbfc3469831e (patch) | |
| tree | ab821f37fca36aa9730bed95c0cad5fbf3e9eaa4 /src/libsyntax_ext/deriving | |
| parent | a5c2d0fffaaf0b764c01bc4066e51ffd475ceae9 (diff) | |
| download | rust-59c8a279daf6912b99ba089ff6dafbfc3469831e.tar.gz rust-59c8a279daf6912b99ba089ff6dafbfc3469831e.zip | |
Replace push loops with collect() and extend() where possible
Diffstat (limited to 'src/libsyntax_ext/deriving')
| -rw-r--r-- | src/libsyntax_ext/deriving/decodable.rs | 4 | ||||
| -rw-r--r-- | src/libsyntax_ext/deriving/generic/mod.rs | 17 | ||||
| -rw-r--r-- | src/libsyntax_ext/deriving/hash.rs | 5 |
3 files changed, 12 insertions, 14 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 ¶m.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)) } |
