From 9c1d5d155e8c08253fef683f63ef223448ff3f8f Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Sun, 10 Mar 2024 11:27:59 +0900 Subject: [PATCH] index: remove HRTB stuff by implementing RevWalkIndex for CompositeIndex --- lib/src/default_index/rev_walk.rs | 28 ++++++++++++-------------- lib/src/default_index/revset_engine.rs | 4 ++-- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/lib/src/default_index/rev_walk.rs b/lib/src/default_index/rev_walk.rs index 0758fa4dd..9c291f919 100644 --- a/lib/src/default_index/rev_walk.rs +++ b/lib/src/default_index/rev_walk.rs @@ -40,10 +40,9 @@ pub(super) trait RevWalk { // to be reimplemented. /// Reattaches the underlying `index`. - fn attach(self, index: I) -> RevWalkBorrowedIndexIter + fn attach(self, index: &I) -> RevWalkBorrowedIndexIter<'_, I, Self> where Self: Sized, - I: Sized, { RevWalkBorrowedIndexIter { index, walk: self } } @@ -52,28 +51,27 @@ pub(super) trait RevWalk { /// Adapter that turns `RevWalk` into `Iterator` by attaching borrowed `index`. #[derive(Clone, Debug)] #[must_use] -pub(super) struct RevWalkBorrowedIndexIter { - // TODO: `index: I` will be a reference type. - index: I, +pub(super) struct RevWalkBorrowedIndexIter<'a, I: ?Sized, W> { + index: &'a I, walk: W, } -impl RevWalkBorrowedIndexIter { +impl RevWalkBorrowedIndexIter<'_, I, W> { /// Turns into `'static`-lifetime walk object by detaching the index. pub fn detach(self) -> W { self.walk } } -impl> Iterator for RevWalkBorrowedIndexIter { +impl> Iterator for RevWalkBorrowedIndexIter<'_, I, W> { type Item = W::Item; fn next(&mut self) -> Option { - self.walk.next(&self.index) + self.walk.next(self.index) } } -impl> FusedIterator for RevWalkBorrowedIndexIter {} +impl> FusedIterator for RevWalkBorrowedIndexIter<'_, I, W> {} /// Adapter that turns `RevWalk` into `Iterator` by attaching owned `index`. #[derive(Clone, Debug)] @@ -100,7 +98,7 @@ pub(super) trait RevWalkIndex { fn adjacent_positions(&self, pos: Self::Position) -> Self::AdjacentPositions; } -impl RevWalkIndex for &CompositeIndex { +impl RevWalkIndex for CompositeIndex { type Position = IndexPosition; type AdjacentPositions = SmallIndexPositionsVec; @@ -383,7 +381,7 @@ impl<'a> RevWalkBuilder<'a> { } pub(super) type RevWalkAncestors<'a> = - RevWalkBorrowedIndexIter<&'a CompositeIndex, RevWalkImpl>; + RevWalkBorrowedIndexIter<'a, CompositeIndex, RevWalkImpl>; #[derive(Clone)] #[must_use] @@ -420,7 +418,7 @@ impl RevWalk for RevWalkImpl { } pub(super) type RevWalkAncestorsGenerationRange<'a> = - RevWalkBorrowedIndexIter<&'a CompositeIndex, RevWalkGenerationRangeImpl>; + RevWalkBorrowedIndexIter<'a, CompositeIndex, RevWalkGenerationRangeImpl>; pub(super) type RevWalkDescendantsGenerationRange = RevWalkOwnedIndexIter< RevWalkDescendantsIndex, RevWalkGenerationRangeImpl>, @@ -540,7 +538,7 @@ impl RevWalkItemGenerationRange { /// Walks descendants from the roots, in order of ascending index position. pub(super) type RevWalkDescendants<'a> = - RevWalkBorrowedIndexIter<&'a CompositeIndex, RevWalkDescendantsImpl>; + RevWalkBorrowedIndexIter<'a, CompositeIndex, RevWalkDescendantsImpl>; #[derive(Clone)] #[must_use] @@ -561,10 +559,10 @@ impl RevWalkDescendants<'_> { } } -impl RevWalk<&CompositeIndex> for RevWalkDescendantsImpl { +impl RevWalk for RevWalkDescendantsImpl { type Item = IndexPosition; - fn next(&mut self, index: &&CompositeIndex) -> Option { + fn next(&mut self, index: &CompositeIndex) -> Option { while let Some(candidate_pos) = self.candidate_positions.pop() { if self.root_positions.contains(&candidate_pos) || index diff --git a/lib/src/default_index/revset_engine.rs b/lib/src/default_index/revset_engine.rs index 48c69cfa7..ed4cab2a8 100644 --- a/lib/src/default_index/revset_engine.rs +++ b/lib/src/default_index/revset_engine.rs @@ -297,7 +297,7 @@ impl fmt::Debug for RevWalkRevset { impl InternalRevset for RevWalkRevset where - W: for<'index> RevWalk<&'index CompositeIndex, Item = IndexPosition> + Clone, + W: RevWalk + Clone, { fn entries<'a, 'index: 'a>( &'a self, @@ -324,7 +324,7 @@ where impl ToPredicateFn for RevWalkRevset where - W: for<'index> RevWalk<&'index CompositeIndex, Item = IndexPosition> + Clone, + W: RevWalk + Clone, { fn to_predicate_fn<'a, 'index: 'a>( &'a self,