From b6060ce6dd982f6b4ff91d68b12415dee90b9182 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Thu, 22 Aug 2024 19:21:33 +0900 Subject: [PATCH] copies: wrap source path in Option to save allocation Most diff entries should have no copy sources. --- lib/src/copies.rs | 10 +++++----- lib/tests/test_merged_tree.rs | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/src/copies.rs b/lib/src/copies.rs index 01b6732835..6448e7a307 100644 --- a/lib/src/copies.rs +++ b/lib/src/copies.rs @@ -101,8 +101,8 @@ pub struct CopiesTreeDiffEntry { /// Path of `CopiesTreeDiffEntry`. #[derive(Clone, Debug, Eq, PartialEq)] pub struct CopiesTreeDiffEntryPath { - /// The source path. - pub source: RepoPathBuf, + /// The source path if this is a copy or rename. + pub source: Option, /// The target path. pub target: RepoPathBuf, } @@ -110,7 +110,7 @@ pub struct CopiesTreeDiffEntryPath { impl CopiesTreeDiffEntryPath { /// The source path. pub fn source(&self) -> &RepoPath { - &self.source + self.source.as_ref().unwrap_or(&self.target) } /// The target path. @@ -156,7 +156,7 @@ impl Stream for CopiesTreeDiffStream<'_> { } return Poll::Ready(Some(CopiesTreeDiffEntry { path: CopiesTreeDiffEntryPath { - source: diff_entry.path.clone(), + source: None, target: diff_entry.path, }, values: diff_entry.values, @@ -165,7 +165,7 @@ impl Stream for CopiesTreeDiffStream<'_> { return Poll::Ready(Some(CopiesTreeDiffEntry { path: CopiesTreeDiffEntryPath { - source: source.clone(), + source: Some(source.clone()), target: diff_entry.path, }, values: diff_entry.values.and_then(|(_, target_value)| { diff --git a/lib/tests/test_merged_tree.rs b/lib/tests/test_merged_tree.rs index 7b2aa23c27..9b7208eb07 100644 --- a/lib/tests/test_merged_tree.rs +++ b/lib/tests/test_merged_tree.rs @@ -876,7 +876,7 @@ fn test_diff_copy_tracing() { diff[0].clone(), ( CopiesTreeDiffEntryPath { - source: modified_path.to_owned(), + source: None, target: modified_path.to_owned(), }, ( @@ -889,7 +889,7 @@ fn test_diff_copy_tracing() { diff[1].clone(), ( CopiesTreeDiffEntryPath { - source: modified_path.to_owned(), + source: Some(modified_path.to_owned()), target: copied_path.to_owned(), }, ( @@ -902,7 +902,7 @@ fn test_diff_copy_tracing() { diff[2].clone(), ( CopiesTreeDiffEntryPath { - source: removed_path.to_owned(), + source: Some(removed_path.to_owned()), target: added_path.to_owned(), }, (