diff options
author | Blaž Hrastnik | 2021-07-19 02:19:05 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2021-07-19 02:29:51 +0000 |
commit | bf43fabf65fe4062f582e59fe21e92a0b0f48cb8 (patch) | |
tree | 627529c9aa012360faf71046fe7f4cbdf9ee8e4d /helix-core/src/transaction.rs | |
parent | cd65a48635d49ccc2aed55a315c3a33875e13f88 (diff) |
Remove ExactSizeIterator requirement on Transaction::change
Size hint is enough.
Diffstat (limited to 'helix-core/src/transaction.rs')
-rw-r--r-- | helix-core/src/transaction.rs | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/helix-core/src/transaction.rs b/helix-core/src/transaction.rs index 048839b3..e20e550f 100644 --- a/helix-core/src/transaction.rs +++ b/helix-core/src/transaction.rs @@ -473,11 +473,13 @@ impl Transaction { /// Generate a transaction from a set of changes. pub fn change<I>(doc: &Rope, changes: I) -> Self where - I: IntoIterator<Item = Change> + ExactSizeIterator, + I: IntoIterator<Item = Change> + Iterator, { let len = doc.len_chars(); - let mut changeset = ChangeSet::with_capacity(2 * changes.len() + 1); // rough estimate + let (lower, upper) = changes.size_hint(); + let size = upper.unwrap_or(lower); + let mut changeset = ChangeSet::with_capacity(2 * size + 1); // rough estimate // TODO: verify ranges are ordered and not overlapping or change will panic. |