From afb1e1693eaf5c4c66ea9e1006f2eaae7eff5fe6 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Sun, 9 Jul 2023 13:18:35 +0900 Subject: [PATCH] conflicts: simplify inner loop of simplify() a bit --- lib/src/conflicts.rs | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/lib/src/conflicts.rs b/lib/src/conflicts.rs index bc27d6d0b..ee7375d89 100644 --- a/lib/src/conflicts.rs +++ b/lib/src/conflicts.rs @@ -98,19 +98,13 @@ impl Conflict { let mut add_index = 0; while add_index < self.adds.len() { let add = &self.adds[add_index]; - let mut modified = false; - for (remove_index, remove) in self.removes.iter().enumerate() { - if remove == add { - // Move the value to the `add_index-1`th diff, then delete the `remove_index`th - // diff. - self.adds.swap(remove_index + 1, add_index); - self.removes.remove(remove_index); - self.adds.remove(remove_index + 1); - modified = true; - break; - } - } - if !modified { + if let Some(remove_index) = self.removes.iter().position(|remove| remove == add) { + // Move the value to the `add_index-1`th diff, then delete the `remove_index`th + // diff. + self.adds.swap(remove_index + 1, add_index); + self.removes.remove(remove_index); + self.adds.remove(remove_index + 1); + } else { add_index += 1; } }