Skip to content

Commit

Permalink
revset: consolidate early-return condition of PositionsAccumulator
Browse files Browse the repository at this point in the history
Since consume_to() checks the bottom position yielded from the source iterator,
it makes sense to add the same check for the cached positions.
  • Loading branch information
yuja committed Mar 11, 2024
1 parent 93c1a80 commit 64e0be2
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions lib/src/default_index/revset_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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;
};
Expand Down

0 comments on commit 64e0be2

Please sign in to comment.