Skip to content

Commit 2be11dd

Browse files
committed
tree::TreeIter: Implement nth to make jumping ahead more efficient
This means `skip` (which uses `nth`) will also be more efficient.
1 parent 210c661 commit 2be11dd

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/tree.rs

+3
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,9 @@ impl<'tree> Iterator for TreeIter<'tree> {
397397
fn size_hint(&self) -> (usize, Option<usize>) {
398398
self.range.size_hint()
399399
}
400+
fn nth(&mut self, n: usize) -> Option<TreeEntry<'tree>> {
401+
self.range.nth(n).and_then(|i| self.tree.get(i))
402+
}
400403
}
401404
impl<'tree> DoubleEndedIterator for TreeIter<'tree> {
402405
fn next_back(&mut self) -> Option<TreeEntry<'tree>> {

0 commit comments

Comments
 (0)