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.ComponentModel.DataAnnotations;
using System;
using System.ComponentModel.DataAnnotations;
using System.IO;
using System.Threading.Tasks;
@ -31,7 +32,7 @@ namespace SourceGit.ViewModels
{
_repo = repo;
_revision = commit.SHA;
_saveFile = $"archive-{commit.SHA.Substring(0, 10)}.zip";
_saveFile = $"archive-{commit.SHA.AsSpan().Slice(0, 10)}.zip";
BasedOn = commit;
}

View file

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Avalonia.Threading;
@ -30,7 +31,7 @@ namespace SourceGit.ViewModels
{
_repo = repo;
Title = $"{file} @ {revision.Substring(0, 10)}";
Title = $"{file} @ {revision.AsSpan().Slice(0, 10)}";
Task.Run(() =>
{
var result = new Commands.Blame(repo, file, revision).Result();

View file

@ -1,4 +1,4 @@
using System;
using System;
using System.IO;
using Avalonia.Collections;
@ -584,7 +584,7 @@ namespace SourceGit.ViewModels
var home = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
var prefixLen = home.EndsWith('/') ? home.Length - 1 : home.Length;
if (path.StartsWith(home, StringComparison.Ordinal))
path = "~" + path.Substring(prefixLen);
path = $"~{path.AsSpan().Slice(prefixLen)}";
}
Title = $"[{workspace}] {name} ({path})";