merged_tree: drop outer loop in TreeDiffStreamImpl::poll_next()

As suggested by Yuya. I also added a comment and an assertion in the
case where return `Poll::Pending`.
This commit is contained in:
Martin von Zweigbergk 2023-11-06 23:16:22 -08:00 committed by Martin von Zweigbergk
parent d989d4093d
commit c77417d4e4

View file

@ -1176,7 +1176,6 @@ impl Stream for TreeDiffStreamImpl<'_> {
type Item = (RepoPath, BackendResult<(MergedTreeValue, MergedTreeValue)>);
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
while !(self.items.is_empty() && self.pending_trees.is_empty()) {
// Go through all pending tree futures and poll them.
let mut pending_index = 0;
while pending_index < self.pending_trees.len()
@ -1208,29 +1207,30 @@ impl Stream for TreeDiffStreamImpl<'_> {
}
// Now emit the first file, or the first tree that completed with an error
while let Some(entry) = self.items.first_entry() {
if let Some(entry) = self.items.first_entry() {
match entry.get() {
Err(_) => {
// File or tree with error
let (key, result) = entry.remove_entry();
return Poll::Ready(Some((key.path, result)));
Poll::Ready(Some((key.path, result)))
}
Ok((before, after)) if !before.is_tree() && !after.is_tree() => {
// A diff with no trees involved
let (key, result) = entry.remove_entry();
return Poll::Ready(Some((key.path, result)));
Poll::Ready(Some((key.path, result)))
}
_ => {
if !self.pending_trees.is_empty() {
return Poll::Pending;
// The first entry has a tree on at least one side (before or after). We need to
// wait for that future to complete.
assert!(!self.pending_trees.is_empty());
Poll::Pending
}
}
};
}
}
} else {
Poll::Ready(None)
}
}
}
/// Helps with writing trees with conflicts. You start by creating an instance
/// of this type with one or more base trees. You then add overrides on top. The