perf: minimize temporary strings for better performance (#1255)

This commit is contained in:
qiufengshe 2025-04-29 09:33:14 +08:00 committed by GitHub
parent 53a55467f1
commit 48bb8e91de
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 35 additions and 23 deletions

View file

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
@ -147,9 +148,9 @@ namespace SourceGit.Models
public void GenerateNewPatchFromSelection(Change change, string fileBlobGuid, TextDiffSelection selection, bool revert, string output)
{
var isTracked = !string.IsNullOrEmpty(fileBlobGuid);
var fileGuid = isTracked ? fileBlobGuid.Substring(0, 8) : "00000000";
var fileGuid = isTracked ? fileBlobGuid.AsSpan().Slice(0, 8) : "00000000".AsSpan();
var builder = new StringBuilder();
var builder = new StringBuilder(512);
builder.Append("diff --git a/").Append(change.Path).Append(" b/").Append(change.Path).Append('\n');
if (!revert && !isTracked)
builder.Append("new file mode 100644\n");