about summary refs log tree commit diff
diff options
context:
space:
mode:
authorCameron Steffen <cam.steffen94@gmail.com>2021-11-01 14:12:17 -0500
committerCameron Steffen <cam.steffen94@gmail.com>2021-11-06 14:28:08 -0500
commit9f6a58e86b00a8ff22f852c1162e3d3107d0755b (patch)
tree2ce328dd5e4bd2d43560aa7ab90a8df84b3efa10
parenta9a24d510698c3aafd6f7e1b974b70ac94e0a18b (diff)
downloadrust-9f6a58e86b00a8ff22f852c1162e3d3107d0755b.tar.gz
rust-9f6a58e86b00a8ff22f852c1162e3d3107d0755b.zip
Factor out some Vecs
-rw-r--r--compiler/rustc_builtin_macros/src/format.rs15
1 files 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<ast::Expr> {
-        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::<usize>() + 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:
         //