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/format.rs | |
| 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/format.rs')
| -rw-r--r-- | src/libsyntax_ext/format.rs | 15 |
1 files changed, 7 insertions, 8 deletions
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()) |
