Skip to content

Commit

Permalink
copies: return early from CopiesTreeDiffStream::poll_next() on Pendin…
Browse files Browse the repository at this point in the history
…g/None
  • Loading branch information
yuja committed Aug 21, 2024
1 parent e9a052e commit 48a2a76
Showing 1 changed file with 22 additions and 24 deletions.
46 changes: 22 additions & 24 deletions lib/src/copies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use std::collections::HashMap;
use std::pin::Pin;
use std::task::{Context, Poll};

use futures::Stream;
use futures::{ready, Stream};

use crate::backend::{BackendResult, CopyRecord};
use crate::merge::MergedTreeValue;
Expand Down Expand Up @@ -121,28 +121,26 @@ impl Stream for CopiesTreeDiffStream<'_> {
type Item = CopiesTreeDiffEntry;

fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
self.inner.as_mut().poll_next(cx).map(|option| {
option.map(|diff_entry| {
let Some(CopyRecord { source, .. }) =
self.copy_records.for_target(&diff_entry.path)
else {
return CopiesTreeDiffEntry {
source: diff_entry.path.clone(),
target: diff_entry.path,
value: diff_entry.value,
};
};

CopiesTreeDiffEntry {
source: source.clone(),
target: diff_entry.path,
value: diff_entry.value.and_then(|(_, target_value)| {
self.source_tree
.path_value(source)
.map(|source_value| (source_value, target_value))
}),
}
})
})
let Some(diff_entry) = ready!(self.inner.as_mut().poll_next(cx)) else {
return Poll::Ready(None);
};

let Some(CopyRecord { source, .. }) = self.copy_records.for_target(&diff_entry.path) else {
return Poll::Ready(Some(CopiesTreeDiffEntry {
source: diff_entry.path.clone(),
target: diff_entry.path,
value: diff_entry.value,
}));
};

Poll::Ready(Some(CopiesTreeDiffEntry {
source: source.clone(),
target: diff_entry.path,
value: diff_entry.value.and_then(|(_, target_value)| {
self.source_tree
.path_value(source)
.map(|source_value| (source_value, target_value))
}),
}))
}
}

0 comments on commit 48a2a76

Please sign in to comment.