conflicts: simplify inner loop of simplify() a bit

This commit is contained in:
Yuya Nishihara 2023-07-09 13:18:35 +09:00
parent aac5b7aa25
commit afb1e1693e

View file

@ -98,19 +98,13 @@ impl<T> Conflict<T> {
let mut add_index = 0; let mut add_index = 0;
while add_index < self.adds.len() { while add_index < self.adds.len() {
let add = &self.adds[add_index]; let add = &self.adds[add_index];
let mut modified = false; if let Some(remove_index) = self.removes.iter().position(|remove| remove == add) {
for (remove_index, remove) in self.removes.iter().enumerate() { // Move the value to the `add_index-1`th diff, then delete the `remove_index`th
if remove == add { // diff.
// Move the value to the `add_index-1`th diff, then delete the `remove_index`th self.adds.swap(remove_index + 1, add_index);
// diff. self.removes.remove(remove_index);
self.adds.swap(remove_index + 1, add_index); self.adds.remove(remove_index + 1);
self.removes.remove(remove_index); } else {
self.adds.remove(remove_index + 1);
modified = true;
break;
}
}
if !modified {
add_index += 1; add_index += 1;
} }
} }