diff --git a/crates/buffer/src/lib.rs b/crates/buffer/src/lib.rs index 301cc1478c..fad83e901a 100644 --- a/crates/buffer/src/lib.rs +++ b/crates/buffer/src/lib.rs @@ -317,7 +317,7 @@ struct Edits<'a, D: TextDimension<'a>, F: FnMut(&FragmentSummary) -> bool> { deleted_cursor: rope::Cursor<'a>, fragments_cursor: Option>, undos: &'a UndoMap, - since: clock::Global, + since: &'a clock::Global, old_end: D, new_end: D, } @@ -1365,7 +1365,10 @@ impl Buffer { }) } - pub fn edits_since<'a, D>(&'a self, since: clock::Global) -> impl 'a + Iterator> + pub fn edits_since<'a, D>( + &'a self, + since: &'a clock::Global, + ) -> impl 'a + Iterator> where D: 'a + TextDimension<'a> + Ord, { @@ -1603,7 +1606,10 @@ impl Snapshot { self.content().anchor_at(position, Bias::Right) } - pub fn edits_since<'a, D>(&'a self, since: clock::Global) -> impl 'a + Iterator> + pub fn edits_since<'a, D>( + &'a self, + since: &'a clock::Global, + ) -> impl 'a + Iterator> where D: 'a + TextDimension<'a> + Ord, { @@ -1935,17 +1941,15 @@ impl<'a> Content<'a> { } } - // TODO: take a reference to clock::Global. - pub fn edits_since(&self, since: clock::Global) -> impl 'a + Iterator> + pub fn edits_since(&self, since: &'a clock::Global) -> impl 'a + Iterator> where D: 'a + TextDimension<'a> + Ord, { - let since_2 = since.clone(); - let fragments_cursor = if since == *self.version { + let fragments_cursor = if since == self.version { None } else { Some(self.fragments.filter( - move |summary| summary.max_version.changed_since(&since_2), + move |summary| summary.max_version.changed_since(since), &None, )) }; diff --git a/crates/buffer/src/tests.rs b/crates/buffer/src/tests.rs index 5cbc36a8f5..68d6e6aa35 100644 --- a/crates/buffer/src/tests.rs +++ b/crates/buffer/src/tests.rs @@ -78,7 +78,7 @@ fn test_random_edits(mut rng: StdRng) { for mut old_buffer in buffer_versions { let edits = buffer - .edits_since::(old_buffer.version.clone()) + .edits_since::(&old_buffer.version) .collect::>(); log::info!( diff --git a/crates/editor/src/display_map/fold_map.rs b/crates/editor/src/display_map/fold_map.rs index 5ff2d3db6b..8a5b4c5584 100644 --- a/crates/editor/src/display_map/fold_map.rs +++ b/crates/editor/src/display_map/fold_map.rs @@ -261,7 +261,7 @@ impl FoldMap { }, ); let edits = buffer - .edits_since(last_sync.version) + .edits_since(&last_sync.version) .map(Into::into) .collect::>(); if edits.is_empty() { @@ -1344,7 +1344,7 @@ mod tests { let edit_count = rng.gen_range(1..=5); buffer.randomly_edit(&mut rng, edit_count); buffer - .edits_since::(start_version) + .edits_since::(&start_version) .collect::>() }); log::info!("editing {:?}", edits); diff --git a/crates/language/src/lib.rs b/crates/language/src/lib.rs index 02744ceb79..2bbea10967 100644 --- a/crates/language/src/lib.rs +++ b/crates/language/src/lib.rs @@ -360,7 +360,7 @@ impl Buffer { content_changes: snapshot .buffer_snapshot .edits_since::<(PointUtf16, usize)>( - prev_snapshot.buffer_snapshot.version().clone(), + prev_snapshot.buffer_snapshot.version(), ) .map(|edit| { let edit_start = edit.new.start.0; @@ -616,7 +616,7 @@ impl Buffer { } fn interpolate_tree(&self, tree: &mut SyntaxTree) { - for edit in self.edits_since::<(usize, Point)>(tree.version.clone()) { + for edit in self.edits_since::<(usize, Point)>(&tree.version) { let (bytes, lines) = edit.flatten(); tree.tree.edit(&InputEdit { start_byte: bytes.new.start, @@ -672,7 +672,7 @@ impl Buffer { diagnostics.sort_unstable_by_key(|d| (d.range.start, d.range.end)); self.diagnostics = { let mut edits_since_save = content - .edits_since::(self.saved_version.clone()) + .edits_since::(&self.saved_version) .peekable(); let mut last_edit_old_end = PointUtf16::zero(); let mut last_edit_new_end = PointUtf16::zero(); @@ -1081,7 +1081,7 @@ impl Buffer { ) -> Result<()> { if let Some(start_version) = self.text.end_transaction_at(selection_set_ids, now) { let was_dirty = start_version != self.saved_version; - self.did_edit(start_version, was_dirty, cx); + self.did_edit(&start_version, was_dirty, cx); } Ok(()) } @@ -1222,7 +1222,7 @@ impl Buffer { fn did_edit( &mut self, - old_version: clock::Global, + old_version: &clock::Global, was_dirty: bool, cx: &mut ModelContext, ) { @@ -1298,7 +1298,7 @@ impl Buffer { let was_dirty = self.is_dirty(); let old_version = self.version.clone(); self.text.apply_ops(ops)?; - self.did_edit(old_version, was_dirty, cx); + self.did_edit(&old_version, was_dirty, cx); // Notify independently of whether the buffer was edited as the operations could include a // selection update. cx.notify(); @@ -1330,7 +1330,7 @@ impl Buffer { self.send_operation(operation, cx); } - self.did_edit(old_version, was_dirty, cx); + self.did_edit(&old_version, was_dirty, cx); } pub fn redo(&mut self, cx: &mut ModelContext) { @@ -1341,7 +1341,7 @@ impl Buffer { self.send_operation(operation, cx); } - self.did_edit(old_version, was_dirty, cx); + self.did_edit(&old_version, was_dirty, cx); } }