about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPaul Trojahn <paul.trojahn@gmail.com>2021-06-03 19:24:48 +0200
committerPaul Trojahn <paul.trojahn@gmail.com>2021-08-31 14:51:16 +0200
commit7bcc9ae422e03cfc7855363c7e39cf737b8d3ed6 (patch)
treea2c864a1c626363e6528ca9672857e136ac95298
parent5998c2e9adfb01f40ea9d0169488fbdaad10b035 (diff)
downloadrust-7bcc9ae422e03cfc7855363c7e39cf737b8d3ed6.tar.gz
rust-7bcc9ae422e03cfc7855363c7e39cf737b8d3ed6.zip
Avoid cloning LocalDecls
-rw-r--r--compiler/rustc_middle/src/mir/mod.rs5
-rw-r--r--compiler/rustc_mir/src/transform/inline.rs8
2 files changed, 6 insertions, 7 deletions
diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs
index b66995afc6d..17392c0ceb1 100644
--- a/compiler/rustc_middle/src/mir/mod.rs
+++ b/compiler/rustc_middle/src/mir/mod.rs
@@ -427,6 +427,11 @@ impl<'tcx> Body<'tcx> {
         (arg_count + 1..local_count).map(Local::new)
     }
 
+    #[inline]
+    pub fn drain_vars_and_temps<'a>(&'a mut self) -> impl Iterator<Item = LocalDecl<'tcx>> + 'a {
+        self.local_decls.drain(self.arg_count + 1..)
+    }
+
     /// Changes a statement to a nop. This is both faster than deleting instructions and avoids
     /// invalidating statement indices in `Location`s.
     pub fn make_statement_nop(&mut self, location: Location) {
diff --git a/compiler/rustc_mir/src/transform/inline.rs b/compiler/rustc_mir/src/transform/inline.rs
index c333667b3ad..8e9da31eba1 100644
--- a/compiler/rustc_mir/src/transform/inline.rs
+++ b/compiler/rustc_mir/src/transform/inline.rs
@@ -607,13 +607,7 @@ impl Inliner<'tcx> {
                 }
 
                 // Insert all of the (mapped) parts of the callee body into the caller.
-                caller_body.local_decls.extend(
-                    // FIXME(eddyb) make `Range<Local>` iterable so that we can use
-                    // `callee_body.local_decls.drain(callee_body.vars_and_temps())`
-                    callee_body
-                        .vars_and_temps_iter()
-                        .map(|local| callee_body.local_decls[local].clone()),
-                );
+                caller_body.local_decls.extend(callee_body.drain_vars_and_temps());
                 caller_body.source_scopes.extend(&mut callee_body.source_scopes.drain(..));
                 caller_body.var_debug_info.append(&mut callee_body.var_debug_info);
                 caller_body.basic_blocks_mut().extend(callee_body.basic_blocks_mut().drain(..));