Take a &clock::Global instead of cloning in edits_since

This commit is contained in:
Antonio Scandurra 2021-11-01 10:48:20 +01:00
parent 2919cbe9cb
commit 6e5ec2a00d
4 changed files with 23 additions and 19 deletions

View file

@ -317,7 +317,7 @@ struct Edits<'a, D: TextDimension<'a>, F: FnMut(&FragmentSummary) -> bool> {
deleted_cursor: rope::Cursor<'a>, deleted_cursor: rope::Cursor<'a>,
fragments_cursor: Option<FilterCursor<'a, F, Fragment, FragmentTextSummary>>, fragments_cursor: Option<FilterCursor<'a, F, Fragment, FragmentTextSummary>>,
undos: &'a UndoMap, undos: &'a UndoMap,
since: clock::Global, since: &'a clock::Global,
old_end: D, old_end: D,
new_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<Item = Edit<D>> pub fn edits_since<'a, D>(
&'a self,
since: &'a clock::Global,
) -> impl 'a + Iterator<Item = Edit<D>>
where where
D: 'a + TextDimension<'a> + Ord, D: 'a + TextDimension<'a> + Ord,
{ {
@ -1603,7 +1606,10 @@ impl Snapshot {
self.content().anchor_at(position, Bias::Right) self.content().anchor_at(position, Bias::Right)
} }
pub fn edits_since<'a, D>(&'a self, since: clock::Global) -> impl 'a + Iterator<Item = Edit<D>> pub fn edits_since<'a, D>(
&'a self,
since: &'a clock::Global,
) -> impl 'a + Iterator<Item = Edit<D>>
where where
D: 'a + TextDimension<'a> + Ord, D: 'a + TextDimension<'a> + Ord,
{ {
@ -1935,17 +1941,15 @@ impl<'a> Content<'a> {
} }
} }
// TODO: take a reference to clock::Global. pub fn edits_since<D>(&self, since: &'a clock::Global) -> impl 'a + Iterator<Item = Edit<D>>
pub fn edits_since<D>(&self, since: clock::Global) -> impl 'a + Iterator<Item = Edit<D>>
where where
D: 'a + TextDimension<'a> + Ord, 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 None
} else { } else {
Some(self.fragments.filter( Some(self.fragments.filter(
move |summary| summary.max_version.changed_since(&since_2), move |summary| summary.max_version.changed_since(since),
&None, &None,
)) ))
}; };

View file

@ -78,7 +78,7 @@ fn test_random_edits(mut rng: StdRng) {
for mut old_buffer in buffer_versions { for mut old_buffer in buffer_versions {
let edits = buffer let edits = buffer
.edits_since::<usize>(old_buffer.version.clone()) .edits_since::<usize>(&old_buffer.version)
.collect::<Vec<_>>(); .collect::<Vec<_>>();
log::info!( log::info!(

View file

@ -261,7 +261,7 @@ impl FoldMap {
}, },
); );
let edits = buffer let edits = buffer
.edits_since(last_sync.version) .edits_since(&last_sync.version)
.map(Into::into) .map(Into::into)
.collect::<Vec<_>>(); .collect::<Vec<_>>();
if edits.is_empty() { if edits.is_empty() {
@ -1344,7 +1344,7 @@ mod tests {
let edit_count = rng.gen_range(1..=5); let edit_count = rng.gen_range(1..=5);
buffer.randomly_edit(&mut rng, edit_count); buffer.randomly_edit(&mut rng, edit_count);
buffer buffer
.edits_since::<Point>(start_version) .edits_since::<Point>(&start_version)
.collect::<Vec<_>>() .collect::<Vec<_>>()
}); });
log::info!("editing {:?}", edits); log::info!("editing {:?}", edits);

View file

@ -360,7 +360,7 @@ impl Buffer {
content_changes: snapshot content_changes: snapshot
.buffer_snapshot .buffer_snapshot
.edits_since::<(PointUtf16, usize)>( .edits_since::<(PointUtf16, usize)>(
prev_snapshot.buffer_snapshot.version().clone(), prev_snapshot.buffer_snapshot.version(),
) )
.map(|edit| { .map(|edit| {
let edit_start = edit.new.start.0; let edit_start = edit.new.start.0;
@ -616,7 +616,7 @@ impl Buffer {
} }
fn interpolate_tree(&self, tree: &mut SyntaxTree) { 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(); let (bytes, lines) = edit.flatten();
tree.tree.edit(&InputEdit { tree.tree.edit(&InputEdit {
start_byte: bytes.new.start, start_byte: bytes.new.start,
@ -672,7 +672,7 @@ impl Buffer {
diagnostics.sort_unstable_by_key(|d| (d.range.start, d.range.end)); diagnostics.sort_unstable_by_key(|d| (d.range.start, d.range.end));
self.diagnostics = { self.diagnostics = {
let mut edits_since_save = content let mut edits_since_save = content
.edits_since::<PointUtf16>(self.saved_version.clone()) .edits_since::<PointUtf16>(&self.saved_version)
.peekable(); .peekable();
let mut last_edit_old_end = PointUtf16::zero(); let mut last_edit_old_end = PointUtf16::zero();
let mut last_edit_new_end = PointUtf16::zero(); let mut last_edit_new_end = PointUtf16::zero();
@ -1081,7 +1081,7 @@ impl Buffer {
) -> Result<()> { ) -> Result<()> {
if let Some(start_version) = self.text.end_transaction_at(selection_set_ids, now) { if let Some(start_version) = self.text.end_transaction_at(selection_set_ids, now) {
let was_dirty = start_version != self.saved_version; 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(()) Ok(())
} }
@ -1222,7 +1222,7 @@ impl Buffer {
fn did_edit( fn did_edit(
&mut self, &mut self,
old_version: clock::Global, old_version: &clock::Global,
was_dirty: bool, was_dirty: bool,
cx: &mut ModelContext<Self>, cx: &mut ModelContext<Self>,
) { ) {
@ -1298,7 +1298,7 @@ impl Buffer {
let was_dirty = self.is_dirty(); let was_dirty = self.is_dirty();
let old_version = self.version.clone(); let old_version = self.version.clone();
self.text.apply_ops(ops)?; 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 // Notify independently of whether the buffer was edited as the operations could include a
// selection update. // selection update.
cx.notify(); cx.notify();
@ -1330,7 +1330,7 @@ impl Buffer {
self.send_operation(operation, cx); 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<Self>) { pub fn redo(&mut self, cx: &mut ModelContext<Self>) {
@ -1341,7 +1341,7 @@ impl Buffer {
self.send_operation(operation, cx); self.send_operation(operation, cx);
} }
self.did_edit(old_version, was_dirty, cx); self.did_edit(&old_version, was_dirty, cx);
} }
} }