diff options
author | Nathan Vegdahl | 2021-07-19 05:02:12 +0000 |
---|---|---|
committer | Nathan Vegdahl | 2021-07-19 05:02:12 +0000 |
commit | e462f32723bb61899a390f438d7d856d87fb7614 (patch) | |
tree | e97a9afbf07e2735ba96d62dd5e8f71e1a241fe1 /helix-core/src/transaction.rs | |
parent | 6c038bb0151c6aeb43fc94bd2dc3d516a71d346c (diff) | |
parent | 5292fe0f7df9f1a420744007aa9dd67e7a5a6610 (diff) |
Merge branch 'master' into great_line_ending_and_cursor_range_cleanup
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. |