Use mem::replace instead of mem::swap when it's cleaner.

This commit is contained in:
Dan Gohman
2017-09-05 13:55:33 -07:00
parent 0ac1d0dd94
commit d3712575b5
2 changed files with 3 additions and 6 deletions

View File

@@ -370,8 +370,7 @@ where
debug_assert!(!data.sealed);
// Extract the undef_variables data from the block so that we
// can iterate over it without borrowing the whole builder.
let mut undef_variables = Vec::new();
mem::swap(&mut data.undef_variables, &mut undef_variables);
let undef_variables = mem::replace(&mut data.undef_variables, Vec::new());
(undef_variables, data.ebb)
}
};
@@ -415,8 +414,7 @@ where
// Iterate over the predecessors. To avoid borrowing `self` for the whole loop,
// temporarily detach the predecessors list and replace it with an empty list.
// `use_var`'s traversal won't revisit these predecesors.
let mut preds = Vec::new();
mem::swap(&mut preds, &mut self.predecessors_mut(dest_ebb));
let mut preds = mem::replace(self.predecessors_mut(dest_ebb), Vec::new());
for &(pred, _) in &preds {
// For each predecessor, we query what is the local SSA value corresponding
// to var and we put it as an argument of the branch instruction.