Avoid cloning LocalDecls

This commit is contained in:
Paul Trojahn 2021-06-03 19:24:48 +02:00
parent 5998c2e9ad
commit 7bcc9ae422
2 changed files with 6 additions and 7 deletions

View File

@ -427,6 +427,11 @@ pub fn vars_and_temps_iter(
(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) {

View File

@ -607,13 +607,7 @@ fn dest_needs_borrow(place: Place<'_>) -> bool {
}
// 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(..));