mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-22 20:37:19 -08:00
optimize<Blame, DiffViewer>: using StringBuilder instead of TextBox.AppendText
This commit is contained in:
parent
befe54240a
commit
5584b323de
2 changed files with 21 additions and 14 deletions
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
@ -55,7 +56,7 @@ namespace SourceGit.UI {
|
|||
content.Document.Blocks.Clear();
|
||||
|
||||
if (blame.IsBinary) {
|
||||
lineNumber.Text = "0";
|
||||
lineNumber.Text = "";
|
||||
|
||||
Paragraph p = new Paragraph(new Run("BINARY FILE BLAME NOT SUPPORTED!!!"));
|
||||
p.Margin = new Thickness(0);
|
||||
|
@ -67,9 +68,9 @@ namespace SourceGit.UI {
|
|||
|
||||
content.Document.Blocks.Add(p);
|
||||
} else {
|
||||
List<string> numbers = new List<string>();
|
||||
for (int i = 0; i < blame.LineCount; i++) numbers.Add(i.ToString());
|
||||
lineNumber.Text = string.Join("\n", numbers);
|
||||
var numbers = new StringBuilder();
|
||||
for (int i = 0; i < blame.LineCount; i++) numbers.AppendLine(i.ToString());
|
||||
lineNumber.Text = numbers.ToString();
|
||||
numbers.Clear();
|
||||
|
||||
for (int i = 0; i < blame.Blocks.Count; i++) {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
@ -119,10 +120,15 @@ namespace SourceGit.UI {
|
|||
leftText.Document.Blocks.Clear();
|
||||
rightText.Document.Blocks.Clear();
|
||||
|
||||
foreach (var b in rs.Blocks) ShowBlock(b);
|
||||
var leftLineNumberBuilder = new StringBuilder();
|
||||
var rightLineNumberBuilder = new StringBuilder();
|
||||
|
||||
foreach (var b in rs.Blocks) ShowBlock(b, leftLineNumberBuilder, rightLineNumberBuilder);
|
||||
|
||||
leftText.Document.PageWidth = minWidth + 16;
|
||||
rightText.Document.PageWidth = minWidth + 16;
|
||||
leftLineNumber.Text = leftLineNumberBuilder.ToString();
|
||||
rightLineNumber.Text = rightLineNumberBuilder.ToString();
|
||||
leftText.ScrollToHome();
|
||||
});
|
||||
}
|
||||
|
@ -175,7 +181,7 @@ namespace SourceGit.UI {
|
|||
/// Make paragraph.
|
||||
/// </summary>
|
||||
/// <param name="b"></param>
|
||||
private void ShowBlock(Git.Diff.Block b) {
|
||||
private void ShowBlock(Git.Diff.Block b, StringBuilder leftNumber, StringBuilder rightNumber) {
|
||||
var content = b.Builder.ToString();
|
||||
|
||||
Paragraph p = new Paragraph(new Run(content));
|
||||
|
@ -220,15 +226,15 @@ namespace SourceGit.UI {
|
|||
case Git.Diff.Side.Left:
|
||||
leftText.Document.Blocks.Add(p);
|
||||
for (int i = 0; i < b.Count; i++) {
|
||||
if (b.CanShowNumber) leftLineNumber.AppendText($"{i + b.LeftStart}\n");
|
||||
else leftLineNumber.AppendText("\n");
|
||||
if (b.CanShowNumber) leftNumber.AppendLine($"{i + b.LeftStart}");
|
||||
else leftNumber.AppendLine();
|
||||
}
|
||||
break;
|
||||
case Git.Diff.Side.Right:
|
||||
rightText.Document.Blocks.Add(p);
|
||||
for (int i = 0; i < b.Count; i++) {
|
||||
if (b.CanShowNumber) rightLineNumber.AppendText($"{i + b.RightStart}\n");
|
||||
else rightLineNumber.AppendText("\n");
|
||||
if (b.CanShowNumber) rightNumber.AppendLine($"{i + b.RightStart}");
|
||||
else rightNumber.AppendLine();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
@ -246,11 +252,11 @@ namespace SourceGit.UI {
|
|||
|
||||
for (int i = 0; i < b.Count; i++) {
|
||||
if (b.Mode != Git.Diff.LineMode.Indicator) {
|
||||
leftLineNumber.AppendText($"{i + b.LeftStart}\n");
|
||||
rightLineNumber.AppendText($"{i + b.RightStart}\n");
|
||||
leftNumber.AppendLine($"{i + b.LeftStart}");
|
||||
rightNumber.AppendLine($"{i + b.RightStart}");
|
||||
} else {
|
||||
leftLineNumber.AppendText("\n");
|
||||
rightLineNumber.AppendText("\n");
|
||||
leftNumber.AppendLine();
|
||||
rightNumber.AppendLine();
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
|
Loading…
Reference in a new issue