optimize<CommitGraph>: add path immediatelly after created and remove the sort function to improve performance

This commit is contained in:
leo 2021-07-29 10:16:44 +08:00
parent 56f4e59f9b
commit d9e670b909

View file

@ -175,6 +175,7 @@ namespace SourceGit.Views.Controls {
offsetX += UNIT_WIDTH; offsetX += UNIT_WIDTH;
major = new PathHelper(commit.Parents[0], isMerged, colorIdx, new Point(offsetX, offsetY)); major = new PathHelper(commit.Parents[0], isMerged, colorIdx, new Point(offsetX, offsetY));
unsolved.Add(major); unsolved.Add(major);
temp.Paths.Add(major.Path);
colorIdx++; colorIdx++;
} }
@ -205,7 +206,9 @@ namespace SourceGit.Views.Controls {
offsetX += UNIT_WIDTH; offsetX += UNIT_WIDTH;
// 防止有下一个提交有ended线时新的分支线与旧线重合 // 防止有下一个提交有ended线时新的分支线与旧线重合
unsolved.Add(new PathHelper(commit.Parents[j], isMerged, colorIdx, position, new Point(offsetX, position.Y + HALF_HEIGHT))); var l = new PathHelper(commit.Parents[j], isMerged, colorIdx, position, new Point(offsetX, position.Y + HALF_HEIGHT));
unsolved.Add(l);
temp.Paths.Add(l.Path);
colorIdx++; colorIdx++;
} }
} }
@ -213,7 +216,6 @@ namespace SourceGit.Views.Controls {
// 处理已终止的线 // 处理已终止的线
foreach (var l in ended) { foreach (var l in ended) {
l.Add(position.X, position.Y, true); l.Add(position.X, position.Y, true);
temp.Paths.Add(l.Path);
unsolved.Remove(l); unsolved.Remove(l);
} }
@ -232,15 +234,10 @@ namespace SourceGit.Views.Controls {
var endY = (commits.Count - 0.5) * UNIT_HEIGHT; var endY = (commits.Count - 0.5) * UNIT_HEIGHT;
if (path.Path.Points.Count == 1 && path.Path.Points[0].Y == endY) continue; if (path.Path.Points.Count == 1 && path.Path.Points[0].Y == endY) continue;
path.Add((i + 0.5) * UNIT_WIDTH, endY, true); path.Add((i + 0.5) * UNIT_WIDTH, endY, true);
temp.Paths.Add(path.Path);
} }
unsolved.Clear(); unsolved.Clear();
// 排序
temp.Paths.Sort((l, h) => l.Points[0].Y.CompareTo(h.Points[0].Y));
Dispatcher.Invoke(() => { Dispatcher.Invoke(() => {
data = temp; data = temp;
InvalidateVisual(); InvalidateVisual();