enhance: only store subject in commits.

It has several advantages:

* reduce the memory costed by histories
* higher performance while parsing commits
* no need to calculate subject every time, which is invoked most frequently to render histories
This commit is contained in:
leo 2024-06-08 12:19:48 +08:00
parent 6426da3289
commit 9e45a8a77d
12 changed files with 67 additions and 65 deletions

View file

@ -12,31 +12,13 @@ namespace SourceGit.Models
public ulong AuthorTime { get; set; } = 0;
public User Committer { get; set; } = User.Invalid;
public ulong CommitterTime { get; set; } = 0;
public string Body { get; set; } = string.Empty;
public string Subject { get; set; } = string.Empty;
public List<string> Parents { get; set; } = new List<string>();
public List<Decorator> Decorators { get; set; } = new List<Decorator>();
public bool HasDecorators => Decorators.Count > 0;
public bool IsMerged { get; set; } = false;
public Thickness Margin { get; set; } = new Thickness(0);
public string Subject
{
get
{
var end = Body.IndexOf("\r\n\r\n", StringComparison.Ordinal);
if (end == -1)
{
end = Body.IndexOf("\n\n", StringComparison.Ordinal);
if (end > 0)
return Body.Substring(0, end).Replace("\n", "", StringComparison.Ordinal);
return Body.Replace("\n", " ", StringComparison.Ordinal);
}
return Body.Substring(0, end).Replace("\r\n", " ", StringComparison.Ordinal);
}
}
public string AuthorTimeStr => _utcStart.AddSeconds(AuthorTime).ToString("yyyy/MM/dd HH:mm:ss");
public string CommitterTimeStr => _utcStart.AddSeconds(CommitterTime).ToString("yyyy/MM/dd HH:mm:ss");
public string AuthorTimeShortStr => _utcStart.AddSeconds(AuthorTime).ToString("yyyy/MM/dd");