From 991b0e8b686760ecb695c997bd36818d89043f5e Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Thu, 22 Aug 2024 11:59:33 +0900 Subject: [PATCH] merged_tree: keep Arc globally in TreeDiffStreamImpl I'll replace treeN: MergedTree with Merge, and it's simpler to just keep the store by TreeDiffStreamImpl. --- lib/src/merged_tree.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/src/merged_tree.rs b/lib/src/merged_tree.rs index 2f2fc20e3..5416511f6 100644 --- a/lib/src/merged_tree.rs +++ b/lib/src/merged_tree.rs @@ -849,6 +849,7 @@ impl Iterator for TreeDiffIterator<'_> { /// Stream of differences between two trees. pub struct TreeDiffStreamImpl<'matcher> { + store: Arc, matcher: &'matcher dyn Matcher, /// Pairs of tree values that may or may not be ready to emit, sorted in the /// order we want to emit them. If either side is a tree, there will be @@ -926,7 +927,9 @@ impl<'matcher> TreeDiffStreamImpl<'matcher> { matcher: &'matcher dyn Matcher, max_concurrent_reads: usize, ) -> Self { + assert!(Arc::ptr_eq(tree1.store(), tree2.store())); let mut stream = Self { + store: tree1.store().clone(), matcher, items: BTreeMap::new(), pending_trees: VecDeque::new(), @@ -1007,9 +1010,9 @@ impl<'matcher> TreeDiffStreamImpl<'matcher> { // If the path was a tree on either side of the diff, read those trees. if tree_matches { let before_tree_future = - Self::tree(tree1.store().clone(), path.clone(), before.cloned()); + Self::tree(self.store.clone(), path.clone(), before.cloned()); let after_tree_future = - Self::tree(tree2.store().clone(), path.clone(), after.cloned()); + Self::tree(self.store.clone(), path.clone(), after.cloned()); let both_trees_future = async { futures::try_join!(before_tree_future, after_tree_future) }; self.pending_trees