on master help sign in
Avoid collect() by accepting iterators into Transaction::change.
0427acdBlaž Hrastnik
helix-core/src/commands.rs+1−1
@@ -155,7 +155,7 @@ pub fn open_below(state: &mut State, _count: usize) {
155 0,
155 0,
156 );
156 );
157
157
158− let transaction = Transaction::change(state, changes.collect()).with_selection(selection);
158+ let transaction = Transaction::change(state, changes).with_selection(selection);
159
159
160 transaction.apply(state);
160 transaction.apply(state);
161 // TODO: need to store into history if successful
161 // TODO: need to store into history if successful
helix-core/src/transaction.rs+5−3
@@ -353,8 +353,10 @@ impl Transaction {
353 }
353 }
354
354
355 /// Generate a transaction from a set of changes.
355 /// 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+ {
358 let len = state.doc.len_chars();
360 let len = state.doc.len_chars();
359 let mut acc = Vec::with_capacity(2 * changes.len() + 1);
361 let mut acc = Vec::with_capacity(2 * changes.len() + 1);
360
362
@@ -381,7 +383,7 @@ impl Transaction {
381 where
383 where
382 F: Fn(&SelectionRange) -> Change,
384 F: Fn(&SelectionRange) -> Change,
383 {
385 {
384− Self::change(state, state.selection.ranges.iter().map(f).collect())
386+ Self::change(state, state.selection.ranges.iter().map(f))
385 }
387 }
386
388
387 /// Insert text at each selection head.
389 /// Insert text at each selection head.