1
Fork 0

Introduced Cursor::next_with_spacing_ref.

This lets us clone just the parts within a `TokenTree` that need
cloning, rather than the entire thing. This is a surprisingly large
performance win, up to 4% on `async-std-1.10.0`.
This commit is contained in:
Nicholas Nethercote 2022-04-21 13:49:40 +10:00
parent cc4e3443ec
commit 643e9f707e
2 changed files with 13 additions and 5 deletions

View file

@ -583,6 +583,14 @@ impl Cursor {
})
}
#[inline]
pub fn next_with_spacing_ref(&mut self) -> Option<&TreeAndSpacing> {
self.stream.0.get(self.index).map(|tree| {
self.index += 1;
tree
})
}
pub fn index(&self) -> usize {
self.index
}