Skip to content

Commit

Permalink
merged_tree: remove redundant .clone() from TreeDiffStreamImpl::new()
Browse files Browse the repository at this point in the history
  • Loading branch information
yuja committed Nov 30, 2024
1 parent d649f82 commit fb670d4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 29 deletions.
35 changes: 15 additions & 20 deletions lib/src/merged_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,8 @@ impl MergedTree {
)))
} else {
Box::pin(TreeDiffStreamImpl::new(
self.trees.clone(),
other.trees.clone(),
&self.trees,
&other.trees,
matcher,
concurrency,
))
Expand Down Expand Up @@ -922,8 +922,8 @@ impl<'matcher> TreeDiffStreamImpl<'matcher> {
/// Creates a iterator over the differences between two trees. Generally
/// prefer `MergedTree::diff_stream()` of calling this directly.
pub fn new(
trees1: Merge<Tree>,
trees2: Merge<Tree>,
trees1: &Merge<Tree>,
trees2: &Merge<Tree>,
matcher: &'matcher dyn Matcher,
max_concurrent_reads: usize,
) -> Self {
Expand All @@ -936,7 +936,7 @@ impl<'matcher> TreeDiffStreamImpl<'matcher> {
max_concurrent_reads,
max_queued_items: 10000,
};
stream.add_dir_diff_items(RepoPathBuf::root(), Ok((trees1, trees2)));
stream.add_dir_diff_items(RepoPath::root(), trees1, trees2);
stream
}

Expand Down Expand Up @@ -968,20 +968,8 @@ impl<'matcher> TreeDiffStreamImpl<'matcher> {
}
}

fn add_dir_diff_items(
&mut self,
dir: RepoPathBuf,
tree_diff: BackendResult<(Merge<Tree>, Merge<Tree>)>,
) {
let (trees1, trees2) = match tree_diff {
Ok(trees) => trees,
Err(err) => {
self.items.insert(DiffStreamKey::normal(dir), Err(err));
return;
}
};

for (basename, before, after) in merged_tree_entry_diff(&trees1, &trees2) {
fn add_dir_diff_items(&mut self, dir: &RepoPath, trees1: &Merge<Tree>, trees2: &Merge<Tree>) {
for (basename, before, after) in merged_tree_entry_diff(trees1, trees2) {
let path = dir.join(basename);
let tree_before = before.is_tree();
let tree_after = after.is_tree();
Expand Down Expand Up @@ -1049,7 +1037,14 @@ impl<'matcher> TreeDiffStreamImpl<'matcher> {
Ok((Merge::absent(), after)),
);
}
self.add_dir_diff_items(key.path, tree_diff);
match tree_diff {
Ok((trees1, trees2)) => {
self.add_dir_diff_items(&key.path, &trees1, &trees2);
}
Err(err) => {
self.items.insert(DiffStreamKey::normal(key.path), Err(err));
}
}
} else {
pending_index += 1;
}
Expand Down
14 changes: 5 additions & 9 deletions lib/tests/test_merged_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,11 @@ fn diff_stream_equals_iter(tree1: &MergedTree, tree2: &MergedTree, matcher: &dyn
.map(|diff| (diff.path, diff.values.unwrap()))
.collect();
let max_concurrent_reads = 10;
let stream_diff: Vec<_> = TreeDiffStreamImpl::new(
trees1.clone(),
trees2.clone(),
matcher,
max_concurrent_reads,
)
.map(|diff| (diff.path, diff.values.unwrap()))
.collect()
.block_on();
let stream_diff: Vec<_> =
TreeDiffStreamImpl::new(trees1, trees2, matcher, max_concurrent_reads)
.map(|diff| (diff.path, diff.values.unwrap()))
.collect()
.block_on();
assert_eq!(stream_diff, iter_diff);
}

Expand Down

0 comments on commit fb670d4

Please sign in to comment.