Skip to content

Commit 187858f

Browse files
Use Iterator::reduce to compose history transactions
Co-authored-by: Blaž Hrastnik <[email protected]>
1 parent 8f08375 commit 187858f

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

helix-core/src/history.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub struct History {
5454
}
5555

5656
/// A single point in history. See [History] for more information.
57-
#[derive(Debug)]
57+
#[derive(Debug, Clone)]
5858
struct Revision {
5959
parent: usize,
6060
last_child: Option<NonZeroUsize>,
@@ -126,15 +126,13 @@ impl History {
126126
return None;
127127
}
128128

129-
let mut transaction = self.revisions[revision].transaction.clone();
130-
131129
// The bounds are checked in the if condition above:
132-
// `revision + 1` is known to be `<= self.current`.
133-
for revision in &self.revisions[revision + 1..self.current] {
134-
transaction = transaction.compose(revision.transaction.clone());
135-
}
136-
137-
Some(transaction)
130+
// `revision` is known to be `< self.current`.
131+
self.revisions[revision..self.current]
132+
.iter()
133+
.map(|revision| &revision.transaction)
134+
.cloned()
135+
.reduce(|acc, transaction| acc.compose(transaction))
138136
}
139137

140138
/// Undo the last edit.

0 commit comments

Comments
 (0)