Use mem::replace instead of mem::swap when it's cleaner.
This commit is contained in:
@@ -132,8 +132,7 @@ impl CheckerBuilder {
|
|||||||
pub fn finish(&mut self) -> Checker {
|
pub fn finish(&mut self) -> Checker {
|
||||||
// Move directives into the new checker, leaving `self.directives` empty and ready for
|
// Move directives into the new checker, leaving `self.directives` empty and ready for
|
||||||
// building a new checker.
|
// building a new checker.
|
||||||
let mut new_directives = Vec::new();
|
let new_directives = mem::replace(&mut self.directives, Vec::new());
|
||||||
mem::swap(&mut new_directives, &mut self.directives);
|
|
||||||
Checker::new(new_directives)
|
Checker::new(new_directives)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -370,8 +370,7 @@ where
|
|||||||
debug_assert!(!data.sealed);
|
debug_assert!(!data.sealed);
|
||||||
// Extract the undef_variables data from the block so that we
|
// Extract the undef_variables data from the block so that we
|
||||||
// can iterate over it without borrowing the whole builder.
|
// can iterate over it without borrowing the whole builder.
|
||||||
let mut undef_variables = Vec::new();
|
let undef_variables = mem::replace(&mut data.undef_variables, Vec::new());
|
||||||
mem::swap(&mut data.undef_variables, &mut undef_variables);
|
|
||||||
(undef_variables, data.ebb)
|
(undef_variables, data.ebb)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -415,8 +414,7 @@ where
|
|||||||
// Iterate over the predecessors. To avoid borrowing `self` for the whole loop,
|
// Iterate over the predecessors. To avoid borrowing `self` for the whole loop,
|
||||||
// temporarily detach the predecessors list and replace it with an empty list.
|
// temporarily detach the predecessors list and replace it with an empty list.
|
||||||
// `use_var`'s traversal won't revisit these predecesors.
|
// `use_var`'s traversal won't revisit these predecesors.
|
||||||
let mut preds = Vec::new();
|
let mut preds = mem::replace(self.predecessors_mut(dest_ebb), Vec::new());
|
||||||
mem::swap(&mut preds, &mut self.predecessors_mut(dest_ebb));
|
|
||||||
for &(pred, _) in &preds {
|
for &(pred, _) in &preds {
|
||||||
// For each predecessor, we query what is the local SSA value corresponding
|
// 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.
|
// to var and we put it as an argument of the branch instruction.
|
||||||
|
|||||||
Reference in New Issue
Block a user