From f27ac22ba44f894faa9597954976d162f042c9a9 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Fri, 26 May 2023 17:06:55 +0900 Subject: [PATCH] index: unify evaluate_revset() implementations The lifetime is a bit tricky since CompositeIndex is a reference wrapper whereas Index trait has no notion about ownership. --- lib/src/default_index_store.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/src/default_index_store.rs b/lib/src/default_index_store.rs index 111caf3ac..3c105ae55 100644 --- a/lib/src/default_index_store.rs +++ b/lib/src/default_index_store.rs @@ -721,8 +721,7 @@ impl Index for MutableIndexImpl { expression: &ResolvedExpression, store: &Arc, ) -> Result + 'index>, RevsetEvaluationError> { - let revset_impl = default_revset_engine::evaluate(expression, store, CompositeIndex(self))?; - Ok(Box::new(revset_impl)) + CompositeIndex(self).evaluate_revset(expression, store) } } @@ -1039,6 +1038,15 @@ impl<'a> CompositeIndex<'a> { } candidate_positions } + + fn evaluate_revset( + &self, + expression: &ResolvedExpression, + store: &Arc, + ) -> Result + 'a>, RevsetEvaluationError> { + let revset_impl = default_revset_engine::evaluate(expression, store, *self)?; + Ok(Box::new(revset_impl)) + } } impl Index for CompositeIndex<'_> { @@ -1116,8 +1124,7 @@ impl Index for CompositeIndex<'_> { expression: &ResolvedExpression, store: &Arc, ) -> Result + 'index>, RevsetEvaluationError> { - let revset_impl = default_revset_engine::evaluate(expression, store, *self)?; - Ok(Box::new(revset_impl)) + CompositeIndex::evaluate_revset(self, expression, store) } } @@ -2016,8 +2023,7 @@ impl Index for ReadonlyIndexImpl { expression: &ResolvedExpression, store: &Arc, ) -> Result + 'index>, RevsetEvaluationError> { - let revset_impl = default_revset_engine::evaluate(expression, store, CompositeIndex(self))?; - Ok(Box::new(revset_impl)) + CompositeIndex(self).evaluate_revset(expression, store) } }