Skip to content

Commit

Permalink
copies: wrap source path in Option to save allocation
Browse files Browse the repository at this point in the history
Most diff entries should have no copy sources.
  • Loading branch information
yuja committed Aug 23, 2024
1 parent 08262eb commit b6060ce
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions lib/src/copies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,16 @@ 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<RepoPathBuf>,
/// The target path.
pub target: RepoPathBuf,
}

impl CopiesTreeDiffEntryPath {
/// The source path.
pub fn source(&self) -> &RepoPath {
&self.source
self.source.as_ref().unwrap_or(&self.target)
}

/// The target path.
Expand Down Expand Up @@ -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,
Expand All @@ -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)| {
Expand Down
6 changes: 3 additions & 3 deletions lib/tests/test_merged_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
},
(
Expand All @@ -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(),
},
(
Expand All @@ -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(),
},
(
Expand Down

0 comments on commit b6060ce

Please sign in to comment.