From 4107cad80e131ebd4d1d241467d138f35dfd9854 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Fri, 8 Mar 2024 23:13:30 +0900 Subject: [PATCH] index: migrate RevWalkDescendants to new RevWalk trait Just for consistency. Descendants are always evaluated eagerly, so this change isn't strictly needed. --- lib/src/default_index/rev_walk.rs | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/lib/src/default_index/rev_walk.rs b/lib/src/default_index/rev_walk.rs index 3991121de..3945de64a 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