ok/jj
1
0
Fork 0
forked from mirrors/jj

copies: wrap source path in Option to save allocation

Most diff entries should have no copy sources.
This commit is contained in:
Yuya Nishihara 2024-08-22 19:21:33 +09:00
parent 08262eb152
commit b6060ce6dd
2 changed files with 8 additions and 8 deletions

View file

@ -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<RepoPathBuf>,
/// 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)| {

View file

@ -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(),
},
(