From 03eff13d52873ba6dc52209816093a11aa44bb72 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Wed, 23 Nov 2022 17:55:01 +0900 Subject: [PATCH] index: extract a couple of RevWalk helper functions to inner struct --- lib/src/index.rs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/src/index.rs b/lib/src/index.rs index 1e9cdfb7e..6fab3a177 100644 --- a/lib/src/index.rs +++ b/lib/src/index.rs @@ -1017,6 +1017,18 @@ impl<'a> RevWalkQueue<'a> { self.unwanted_count += 1; } + fn push_wanted_parents(&mut self, entry: &IndexEntry<'_>) { + for pos in entry.parent_positions() { + self.push_wanted(pos); + } + } + + fn push_unwanted_parents(&mut self, entry: &IndexEntry<'_>) { + for pos in entry.parent_positions() { + self.push_unwanted(pos); + } + } + fn pop(&mut self) -> Option> { if let Some(x) = self.items.pop() { self.unwanted_count -= !x.is_wanted() as usize; @@ -1068,18 +1080,14 @@ impl<'a> Iterator for RevWalk<'a> { while let Some(item) = self.queue.pop() { self.queue.skip_while_eq(&item.entry.0); if item.is_wanted() { - for parent_pos in item.entry.0.parent_positions() { - self.add_wanted(parent_pos); - } + self.queue.push_wanted_parents(&item.entry.0); return Some(item.entry.0); } else if self.queue.items.len() == self.queue.unwanted_count { // No more wanted entries to walk debug_assert!(!self.queue.items.iter().any(|x| x.is_wanted())); return None; } else { - for parent_pos in item.entry.0.parent_positions() { - self.add_unwanted(parent_pos); - } + self.queue.push_unwanted_parents(&item.entry.0); } }