aboutsummaryrefslogtreecommitdiff
path: root/helix-core/src/transaction.rs
diff options
context:
space:
mode:
authorBlaž Hrastnik2020-09-13 14:12:14 +0000
committerBlaž Hrastnik2020-09-13 14:12:14 +0000
commit0427acd18cc06adec49783818107d1d5e2afc2ab (patch)
tree575a8d89d7805c4fae2c8c71310130bcbe08fbf1 /helix-core/src/transaction.rs
parent2027f69eae5a8b7d25a4613dfddc382f01bcdb78 (diff)
Avoid collect() by accepting iterators into Transaction::change.
Diffstat (limited to 'helix-core/src/transaction.rs')
-rw-r--r--helix-core/src/transaction.rs8
1 files changed, 5 insertions, 3 deletions
diff --git a/helix-core/src/transaction.rs b/helix-core/src/transaction.rs
index 12ed523e..4ecc575a 100644
--- a/helix-core/src/transaction.rs
+++ b/helix-core/src/transaction.rs
@@ -353,8 +353,10 @@ impl Transaction {
}
/// Generate a transaction from a set of changes.
- // TODO: take an owned iter instead of Vec
- pub fn change(state: &State, changes: Vec<Change>) -> Self {
+ pub fn change<I>(state: &State, changes: I) -> Self
+ where
+ I: IntoIterator<Item = Change> + ExactSizeIterator,
+ {
let len = state.doc.len_chars();
let mut acc = Vec::with_capacity(2 * changes.len() + 1);
@@ -381,7 +383,7 @@ impl Transaction {
where
F: Fn(&SelectionRange) -> Change,
{
- Self::change(state, state.selection.ranges.iter().map(f).collect())
+ Self::change(state, state.selection.ranges.iter().map(f))
}
/// Insert text at each selection head.