Skip to content

Commit 1aa0831

Browse files
committed
index: extract RevWalkQueue::pop_if() function
1 parent a363e6b commit 1aa0831

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

lib/src/default_index/rev_walk_queue.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,16 @@ impl<P: Ord, T: Ord> RevWalkQueue<P, T> {
133133
Some(next)
134134
}
135135

136-
pub fn pop_eq(&mut self, pos: &P) -> Option<RevWalkWorkItem<P, T>> {
136+
pub fn pop_if(
137+
&mut self,
138+
predicate: impl FnOnce(&RevWalkWorkItem<P, T>) -> bool,
139+
) -> Option<RevWalkWorkItem<P, T>> {
137140
let next = self.peek()?;
138-
(next.pos == *pos).then(|| self.pop().unwrap())
141+
predicate(next).then(|| self.pop().unwrap())
142+
}
143+
144+
pub fn pop_eq(&mut self, pos: &P) -> Option<RevWalkWorkItem<P, T>> {
145+
self.pop_if(|next| next.pos == *pos)
139146
}
140147

141148
pub fn skip_while_eq(&mut self, pos: &P) {

0 commit comments

Comments
 (0)