From 9f6a58e86b00a8ff22f852c1162e3d3107d0755b Mon Sep 17 00:00:00 2001 From: Cameron Steffen Date: Mon, 1 Nov 2021 14:12:17 -0500 Subject: [PATCH] Factor out some Vecs --- compiler/rustc_builtin_macros/src/format.rs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/compiler/rustc_builtin_macros/src/format.rs b/compiler/rustc_builtin_macros/src/format.rs index 580c3724058..52b00a2bc74 100644 --- a/compiler/rustc_builtin_macros/src/format.rs +++ b/compiler/rustc_builtin_macros/src/format.rs @@ -760,9 +760,9 @@ impl<'a, 'b> Context<'a, 'b> { /// Actually builds the expression which the format_args! block will be /// expanded to. fn into_expr(self) -> P { - 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 args = Vec::with_capacity( + self.arg_unique_types.iter().map(|v| v.len()).sum::() + self.count_args.len(), + ); let mut heads = Vec::with_capacity(self.args.len()); // First, build up the static array which will become our precompiled @@ -783,7 +783,7 @@ impl<'a, 'b> Context<'a, 'b> { // passed to this function. for (i, e) in self.args.into_iter().enumerate() { for arg_ty in self.arg_unique_types[i].iter() { - locals.push(Context::format_arg(self.ecx, self.macsp, e.span, arg_ty, i)); + args.push(Context::format_arg(self.ecx, self.macsp, e.span, arg_ty, i)); } heads.push(self.ecx.expr_addr_of(e.span, e)); } @@ -793,13 +793,10 @@ impl<'a, 'b> Context<'a, 'b> { _ => panic!("should never happen"), }; let span = spans_pos[index]; - counts.push(Context::format_arg(self.ecx, self.macsp, span, &Count, index)); + args.push(Context::format_arg(self.ecx, self.macsp, span, &Count, index)); } - // Now create a vector containing all the arguments - let args = locals.into_iter().chain(counts.into_iter()); - - let args_array = self.ecx.expr_vec(self.macsp, args.collect()); + let args_array = self.ecx.expr_vec(self.macsp, args); // Constructs an AST equivalent to: //