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>,
fragments_cursor: Option<FilterCursor<'a, F, Fragment, FragmentTextSummary>>,
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<Item = Edit<D>>
pub fn edits_since<'a, D>(
&'a self,
since: &'a clock::Global,
) -> impl 'a + Iterator<Item = Edit<D>>
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<Item = Edit<D>>
pub fn edits_since<'a, D>(
&'a self,
since: &'a clock::Global,
) -> impl 'a + Iterator<Item = Edit<D>>
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<D>(&self, since: clock::Global) -> impl 'a + Iterator<Item = Edit<D>>
pub fn edits_since<D>(&self, since: &'a clock::Global) -> impl 'a + Iterator<Item = Edit<D>>
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,
))
};

View file

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