index: migrate RevWalkDescendants to new RevWalk trait

Just for consistency. Descendants are always evaluated eagerly, so this change
isn't strictly needed.
This commit is contained in:
Yuya Nishihara 2024-03-08 23:13:30 +09:00
parent b6cbd8b90b
commit 4107cad80e

View file

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