From 64e0be247729373cbb76750def7c51e4bf22622f Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Mon, 11 Mar 2024 12:36:15 +0900 Subject: [PATCH] revset: consolidate early-return condition of PositionsAccumulator Since consume_to() checks the bottom position yielded from the source iterator, it makes sense to add the same check for the cached positions. --- lib/src/default_index/revset_engine.rs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/lib/src/default_index/revset_engine.rs b/lib/src/default_index/revset_engine.rs index 42ffaae59c..09d8396b10 100644 --- a/lib/src/default_index/revset_engine.rs +++ b/lib/src/default_index/revset_engine.rs @@ -197,14 +197,7 @@ impl<'revset, 'index> PositionsAccumulator<'revset, 'index> { }; let mut inner = self.inner.borrow_mut(); - if let Some(last_position) = inner.consumed_positions.last() { - if last_position > &position { - inner.consume_to(position); - } - } else { - inner.consume_to(position); - } - + inner.consume_to(position); inner .consumed_positions .binary_search_by(|p| p.cmp(&position).reverse()) @@ -226,6 +219,10 @@ struct PositionsAccumulatorInner<'revset> { impl<'revset> PositionsAccumulatorInner<'revset> { /// Consumes positions iterator to a desired position but not deeper. fn consume_to(&mut self, desired_position: IndexPosition) { + let last_position = self.consumed_positions.last(); + if last_position.map_or(false, |&pos| pos <= desired_position) { + return; + } let Some(iter) = self.positions_iter.as_mut() else { return; };