mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-23 20:47:25 -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;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
|
@ -55,7 +56,7 @@ namespace SourceGit.UI {
|
||||||
content.Document.Blocks.Clear();
|
content.Document.Blocks.Clear();
|
||||||
|
|
||||||
if (blame.IsBinary) {
|
if (blame.IsBinary) {
|
||||||
lineNumber.Text = "0";
|
lineNumber.Text = "";
|
||||||
|
|
||||||
Paragraph p = new Paragraph(new Run("BINARY FILE BLAME NOT SUPPORTED!!!"));
|
Paragraph p = new Paragraph(new Run("BINARY FILE BLAME NOT SUPPORTED!!!"));
|
||||||
p.Margin = new Thickness(0);
|
p.Margin = new Thickness(0);
|
||||||
|
@ -67,9 +68,9 @@ namespace SourceGit.UI {
|
||||||
|
|
||||||
content.Document.Blocks.Add(p);
|
content.Document.Blocks.Add(p);
|
||||||
} else {
|
} else {
|
||||||
List<string> numbers = new List<string>();
|
var numbers = new StringBuilder();
|
||||||
for (int i = 0; i < blame.LineCount; i++) numbers.Add(i.ToString());
|
for (int i = 0; i < blame.LineCount; i++) numbers.AppendLine(i.ToString());
|
||||||
lineNumber.Text = string.Join("\n", numbers);
|
lineNumber.Text = numbers.ToString();
|
||||||
numbers.Clear();
|
numbers.Clear();
|
||||||
|
|
||||||
for (int i = 0; i < blame.Blocks.Count; i++) {
|
for (int i = 0; i < blame.Blocks.Count; i++) {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
|
@ -119,10 +120,15 @@ namespace SourceGit.UI {
|
||||||
leftText.Document.Blocks.Clear();
|
leftText.Document.Blocks.Clear();
|
||||||
rightText.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;
|
leftText.Document.PageWidth = minWidth + 16;
|
||||||
rightText.Document.PageWidth = minWidth + 16;
|
rightText.Document.PageWidth = minWidth + 16;
|
||||||
|
leftLineNumber.Text = leftLineNumberBuilder.ToString();
|
||||||
|
rightLineNumber.Text = rightLineNumberBuilder.ToString();
|
||||||
leftText.ScrollToHome();
|
leftText.ScrollToHome();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -175,7 +181,7 @@ namespace SourceGit.UI {
|
||||||
/// Make paragraph.
|
/// Make paragraph.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="b"></param>
|
/// <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();
|
var content = b.Builder.ToString();
|
||||||
|
|
||||||
Paragraph p = new Paragraph(new Run(content));
|
Paragraph p = new Paragraph(new Run(content));
|
||||||
|
@ -220,15 +226,15 @@ namespace SourceGit.UI {
|
||||||
case Git.Diff.Side.Left:
|
case Git.Diff.Side.Left:
|
||||||
leftText.Document.Blocks.Add(p);
|
leftText.Document.Blocks.Add(p);
|
||||||
for (int i = 0; i < b.Count; i++) {
|
for (int i = 0; i < b.Count; i++) {
|
||||||
if (b.CanShowNumber) leftLineNumber.AppendText($"{i + b.LeftStart}\n");
|
if (b.CanShowNumber) leftNumber.AppendLine($"{i + b.LeftStart}");
|
||||||
else leftLineNumber.AppendText("\n");
|
else leftNumber.AppendLine();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Git.Diff.Side.Right:
|
case Git.Diff.Side.Right:
|
||||||
rightText.Document.Blocks.Add(p);
|
rightText.Document.Blocks.Add(p);
|
||||||
for (int i = 0; i < b.Count; i++) {
|
for (int i = 0; i < b.Count; i++) {
|
||||||
if (b.CanShowNumber) rightLineNumber.AppendText($"{i + b.RightStart}\n");
|
if (b.CanShowNumber) rightNumber.AppendLine($"{i + b.RightStart}");
|
||||||
else rightLineNumber.AppendText("\n");
|
else rightNumber.AppendLine();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -246,11 +252,11 @@ namespace SourceGit.UI {
|
||||||
|
|
||||||
for (int i = 0; i < b.Count; i++) {
|
for (int i = 0; i < b.Count; i++) {
|
||||||
if (b.Mode != Git.Diff.LineMode.Indicator) {
|
if (b.Mode != Git.Diff.LineMode.Indicator) {
|
||||||
leftLineNumber.AppendText($"{i + b.LeftStart}\n");
|
leftNumber.AppendLine($"{i + b.LeftStart}");
|
||||||
rightLineNumber.AppendText($"{i + b.RightStart}\n");
|
rightNumber.AppendLine($"{i + b.RightStart}");
|
||||||
} else {
|
} else {
|
||||||
leftLineNumber.AppendText("\n");
|
leftNumber.AppendLine();
|
||||||
rightLineNumber.AppendText("\n");
|
rightNumber.AppendLine();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in a new issue