Skip to content

Commit 7bcc9ae

Browse files
committed
Avoid cloning LocalDecls
1 parent 5998c2e commit 7bcc9ae

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

compiler/rustc_middle/src/mir/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,11 @@ impl<'tcx> Body<'tcx> {
427427
(arg_count + 1..local_count).map(Local::new)
428428
}
429429

430+
#[inline]
431+
pub fn drain_vars_and_temps<'a>(&'a mut self) -> impl Iterator<Item = LocalDecl<'tcx>> + 'a {
432+
self.local_decls.drain(self.arg_count + 1..)
433+
}
434+
430435
/// Changes a statement to a nop. This is both faster than deleting instructions and avoids
431436
/// invalidating statement indices in `Location`s.
432437
pub fn make_statement_nop(&mut self, location: Location) {

compiler/rustc_mir/src/transform/inline.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -607,13 +607,7 @@ impl Inliner<'tcx> {
607607
}
608608

609609
// Insert all of the (mapped) parts of the callee body into the caller.
610-
caller_body.local_decls.extend(
611-
// FIXME(eddyb) make `Range<Local>` iterable so that we can use
612-
// `callee_body.local_decls.drain(callee_body.vars_and_temps())`
613-
callee_body
614-
.vars_and_temps_iter()
615-
.map(|local| callee_body.local_decls[local].clone()),
616-
);
610+
caller_body.local_decls.extend(callee_body.drain_vars_and_temps());
617611
caller_body.source_scopes.extend(&mut callee_body.source_scopes.drain(..));
618612
caller_body.var_debug_info.append(&mut callee_body.var_debug_info);
619613
caller_body.basic_blocks_mut().extend(callee_body.basic_blocks_mut().drain(..));

0 commit comments

Comments
 (0)