diff --git a/asyncgit/src/sync/diff.rs b/asyncgit/src/sync/diff.rs index ee4ac231..cd8b2b57 100644 --- a/asyncgit/src/sync/diff.rs +++ b/asyncgit/src/sync/diff.rs @@ -435,7 +435,7 @@ mod tests { get_diff(repo_path, "foo/bar.txt", false, None).unwrap(); assert_eq!(diff.hunks.len(), 1); - assert_eq!(&*diff.hunks[0].lines[1].content, "test\n"); + assert_eq!(&*diff.hunks[0].lines[1].content, "test"); } #[test] diff --git a/asyncgit/src/sync/staging/stage_tracked.rs b/asyncgit/src/sync/staging/stage_tracked.rs index efb2f15a..99c6fa54 100644 --- a/asyncgit/src/sync/staging/stage_tracked.rs +++ b/asyncgit/src/sync/staging/stage_tracked.rs @@ -100,10 +100,7 @@ mod test { let diff = get_diff(path, "test.txt", true, None).unwrap(); assert_eq!(diff.lines, 3); - assert_eq!( - diff.hunks[0].lines[0].content, - String::from("@@ -1 +1,2 @@\n") - ); + assert_eq!(&*diff.hunks[0].lines[0].content, "@@ -1 +1,2 @@"); } #[test] @@ -142,10 +139,7 @@ c = 4"; let diff = get_diff(path, "test.txt", true, None).unwrap(); assert_eq!(diff.lines, 5); - assert_eq!( - diff.hunks[0].lines[0].content, - String::from("@@ -1,2 +1 @@\n") - ); + assert_eq!(&*diff.hunks[0].lines[0].content, "@@ -1,2 +1 @@"); } #[test] diff --git a/asyncgit/src/sync/utils.rs b/asyncgit/src/sync/utils.rs index 34515c36..52cfcb3d 100644 --- a/asyncgit/src/sync/utils.rs +++ b/asyncgit/src/sync/utils.rs @@ -331,10 +331,7 @@ mod tests { // And that file is test.txt let diff = get_diff(repo_path, "test.txt", true, None).unwrap(); - assert_eq!( - &*diff.hunks[0].lines[0].content, - String::from("@@ -1 +1 @@\n") - ); + assert_eq!(&*diff.hunks[0].lines[0].content, "@@ -1 +1 @@"); } #[test] diff --git a/src/components/commitlist.rs b/src/components/commitlist.rs index 382019a7..ae34745e 100644 --- a/src/components/commitlist.rs +++ b/src/components/commitlist.rs @@ -28,7 +28,7 @@ const ELEMENTS_PER_LINE: usize = 9; /// pub struct CommitList { - title: String, + title: Box, selection: usize, branch: Option, count_total: usize, @@ -61,7 +61,7 @@ impl CommitList { scroll_top: Cell::new(0), theme, key_config, - title: String::from(title), + title: title.into(), } } @@ -258,7 +258,7 @@ impl CommitList { // commit hash txt.push(Span::styled( - Cow::from(e.hash_short.as_str()), + Cow::from(&*e.hash_short), theme.commit_hash(selected), )); @@ -298,7 +298,7 @@ impl CommitList { // commit msg txt.push(Span::styled( - Cow::from(e.msg.as_str()), + Cow::from(&*e.msg), theme.text(true, selected), )); diff --git a/src/components/utils/logitems.rs b/src/components/utils/logitems.rs index 9f21d326..67b83a9a 100644 --- a/src/components/utils/logitems.rs +++ b/src/components/utils/logitems.rs @@ -6,11 +6,16 @@ use crate::components::utils::emojifi_string; static SLICE_OFFSET_RELOAD_THRESHOLD: usize = 100; +type BoxStr = Box; + pub struct LogEntry { + //TODO: cache string representation pub time: DateTime, - pub author: String, - pub msg: String, - pub hash_short: String, + //TODO: use tinyvec here + pub author: BoxStr, + pub msg: BoxStr, + //TODO: use tinyvec here + pub hash_short: BoxStr, pub id: CommitId, } @@ -28,10 +33,10 @@ impl From for LogEntry { emojifi_string(&mut msg); Self { - author, - msg, + author: author.into(), + msg: msg.into(), time, - hash_short: c.id.get_short_string(), + hash_short: c.id.get_short_string().into(), id: c.id, } }