mirror of
https://github.com/gitui-org/gitui
synced 2026-05-23 00:48:35 +00:00
some more immutable string optimizations
and precompute diff line trimming (newlines)
This commit is contained in:
parent
8353dfdd36
commit
9c7ac0f84d
5 changed files with 19 additions and 23 deletions
|
|
@ -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]
|
||||
|
|
|
|||
|
|
@ -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]
|
||||
|
|
|
|||
|
|
@ -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]
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ const ELEMENTS_PER_LINE: usize = 9;
|
|||
|
||||
///
|
||||
pub struct CommitList {
|
||||
title: String,
|
||||
title: Box<str>,
|
||||
selection: usize,
|
||||
branch: Option<String>,
|
||||
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),
|
||||
));
|
||||
|
||||
|
|
|
|||
|
|
@ -6,11 +6,16 @@ use crate::components::utils::emojifi_string;
|
|||
|
||||
static SLICE_OFFSET_RELOAD_THRESHOLD: usize = 100;
|
||||
|
||||
type BoxStr = Box<str>;
|
||||
|
||||
pub struct LogEntry {
|
||||
//TODO: cache string representation
|
||||
pub time: DateTime<Local>,
|
||||
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<CommitInfo> 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,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue