From 25a5f3774699542604d5102c84d0e9e981762f42 Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Tue, 22 Nov 2022 21:13:50 -0600 Subject: [PATCH] Use Iterator::reduce to compose history transactions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Blaž Hrastnik --- helix-core/src/history.rs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/helix-core/src/history.rs b/helix-core/src/history.rs index 8a8702b9cc6aa..c61515db0ea1d 100644 --- a/helix-core/src/history.rs +++ b/helix-core/src/history.rs @@ -126,15 +126,9 @@ impl History { return None; } - let mut transaction = self.revisions[revision].transaction.clone(); - // The bounds are checked in the if condition above: // `revision + 1` is known to be `<= self.current`. - for revision in &self.revisions[revision + 1..self.current] { - transaction = transaction.compose(revision.transaction.clone()); - } - - Some(transaction) + self.revisions[revision..self.current].iter().cloned().reduce(|acc, transaction| acc.compose(transaction)) } /// Undo the last edit.