Skip to content

Commit

Permalink
index: migrate RevWalkDescendants to new RevWalk trait
Browse files Browse the repository at this point in the history
Just for consistency. Descendants are always evaluated eagerly, so this change
isn't strictly needed.
  • Loading branch information
yuja committed Mar 11, 2024
1 parent b6cbd8b commit 4107cad
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions lib/src/default_index/rev_walk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
},
}
}

Expand Down Expand Up @@ -518,10 +520,12 @@ impl RevWalkItemGenerationRange {
}

/// Walks descendants from the roots, in order of ascending index position.
pub(super) type RevWalkDescendants<'a> =
RevWalkBorrowedIndexIter<CompositeIndex<'a>, RevWalkDescendantsImpl>;

#[derive(Clone)]
#[must_use]
pub(super) struct RevWalkDescendants<'a> {
index: CompositeIndex<'a>,
pub(super) struct RevWalkDescendantsImpl {
candidate_positions: Vec<IndexPosition>,
root_positions: HashSet<IndexPosition>,
reachable_positions: HashSet<IndexPosition>,
Expand All @@ -534,18 +538,17 @@ impl RevWalkDescendants<'_> {
/// internal buffer instead.
pub fn collect_positions_set(mut self) -> HashSet<IndexPosition> {
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;

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() {
if self.root_positions.contains(&candidate_pos)
|| self
.index
|| index
.entry_by_pos(candidate_pos)
.parent_positions()
.iter()
Expand All @@ -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
Expand Down

0 comments on commit 4107cad

Please sign in to comment.