diff --git a/lib/src/default_index/rev_walk.rs b/lib/src/default_index/rev_walk.rs index 3991121ded..3945de64a4 100644 --- a/lib/src/default_index/rev_walk.rs +++ b/lib/src/default_index/rev_walk.rs @@ -318,11 +318,13 @@ impl<'a> RevWalkBuilder<'a> { let candidate_positions = self .ancestors_until_roots(root_positions.iter().copied()) .collect(); - RevWalkDescendants { + RevWalkBorrowedIndexIter { index, - candidate_positions, - root_positions, - reachable_positions: HashSet::new(), + walk: RevWalkDescendantsImpl { + candidate_positions, + root_positions, + reachable_positions: HashSet::new(), + }, } } @@ -518,10 +520,12 @@ impl RevWalkItemGenerationRange { } /// Walks descendants from the roots, in order of ascending index position. +pub(super) type RevWalkDescendants<'a> = + RevWalkBorrowedIndexIter, RevWalkDescendantsImpl>; + #[derive(Clone)] #[must_use] -pub(super) struct RevWalkDescendants<'a> { - index: CompositeIndex<'a>, +pub(super) struct RevWalkDescendantsImpl { candidate_positions: Vec, root_positions: HashSet, reachable_positions: HashSet, @@ -534,18 +538,17 @@ impl RevWalkDescendants<'_> { /// internal buffer instead. pub fn collect_positions_set(mut self) -> HashSet { self.by_ref().for_each(drop); - self.reachable_positions + self.walk.reachable_positions } } -impl Iterator for RevWalkDescendants<'_> { +impl RevWalk> for RevWalkDescendantsImpl { type Item = IndexPosition; - fn next(&mut self) -> Option { + fn next(&mut self, index: &CompositeIndex) -> Option { while let Some(candidate_pos) = self.candidate_positions.pop() { if self.root_positions.contains(&candidate_pos) - || self - .index + || index .entry_by_pos(candidate_pos) .parent_positions() .iter() @@ -559,8 +562,6 @@ impl Iterator for RevWalkDescendants<'_> { } } -impl FusedIterator for RevWalkDescendants<'_> {} - /// Computes ancestors set lazily. /// /// This is similar to `RevWalk` functionality-wise, but implemented with the