on master help sign in
Avoid collect() by accepting iterators into Transaction::change.
commit0427acd18cc06adec49783818107d1d5e2afc2ab authorBlaž Hrastnik <blaz@mxxn.io> dateSun 13 Sep 2020, 23:12 (6 years ago) parent2027f69
2 files changed+6−4
helix-core/src/commands.rs+1−1 helix-core/src/transaction.rs+5−3
helix-core/src/commands.rs+1−1
@@ -155,7 +155,7 @@ pub fn open_below(state: &mut State, _count: usize) {
155155 0,
156156 );
157157
158− let transaction = Transaction::change(state, changes.collect()).with_selection(selection);
158+ let transaction = Transaction::change(state, changes).with_selection(selection);
159159
160160 transaction.apply(state);
161161 // TODO: need to store into history if successful
helix-core/src/transaction.rs+5−3
@@ -353,8 +353,10 @@ impl Transaction {
353353 }
354354
355355 /// Generate a transaction from a set of changes.
356− // TODO: take an owned iter instead of Vec
357− pub fn change(state: &State, changes: Vec<Change>) -> Self {
356+ pub fn change<I>(state: &State, changes: I) -> Self
357+ where
358+ I: IntoIterator<Item = Change> + ExactSizeIterator,
359+ {
358360 let len = state.doc.len_chars();
359361 let mut acc = Vec::with_capacity(2 * changes.len() + 1);
360362
@@ -381,7 +383,7 @@ impl Transaction {
381383 where
382384 F: Fn(&SelectionRange) -> Change,
383385 {
384− Self::change(state, state.selection.ranges.iter().map(f).collect())
386+ Self::change(state, state.selection.ranges.iter().map(f))
385387 }
386388
387389 /// Insert text at each selection head.