mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-20 11:44:59 +00:00
perf: minimize temporary strings for better performance (#1292)
This commit is contained in:
parent
5d1601086f
commit
15ee2dac91
3 changed files with 18 additions and 18 deletions
|
@ -1,4 +1,4 @@
|
|||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SourceGit.Models
|
||||
|
@ -22,24 +22,24 @@ namespace SourceGit.Models
|
|||
{
|
||||
if (remote.TryGetVisitURL(out var url))
|
||||
{
|
||||
var trimmedUrl = url;
|
||||
var trimmedUrl = url.AsSpan();
|
||||
if (url.EndsWith(".git"))
|
||||
trimmedUrl = url.Substring(0, url.Length - 4);
|
||||
trimmedUrl = url.AsSpan().Slice(0, url.Length - 4);
|
||||
|
||||
if (url.StartsWith("https://github.com/", StringComparison.Ordinal))
|
||||
outs.Add(new($"Github ({trimmedUrl.Substring(19)})", $"{url}/commit/"));
|
||||
outs.Add(new($"Github ({trimmedUrl.Slice(19)})", $"{url}/commit/"));
|
||||
else if (url.StartsWith("https://gitlab.", StringComparison.Ordinal))
|
||||
outs.Add(new($"GitLab ({trimmedUrl.Substring(trimmedUrl.Substring(15).IndexOf('/') + 16)})", $"{url}/-/commit/"));
|
||||
outs.Add(new($"GitLab ({trimmedUrl.Slice(trimmedUrl.Slice(15).IndexOf('/') + 16)})", $"{url}/-/commit/"));
|
||||
else if (url.StartsWith("https://gitee.com/", StringComparison.Ordinal))
|
||||
outs.Add(new($"Gitee ({trimmedUrl.Substring(18)})", $"{url}/commit/"));
|
||||
outs.Add(new($"Gitee ({trimmedUrl.Slice(18)})", $"{url}/commit/"));
|
||||
else if (url.StartsWith("https://bitbucket.org/", StringComparison.Ordinal))
|
||||
outs.Add(new($"BitBucket ({trimmedUrl.Substring(22)})", $"{url}/commits/"));
|
||||
outs.Add(new($"BitBucket ({trimmedUrl.Slice(22)})", $"{url}/commits/"));
|
||||
else if (url.StartsWith("https://codeberg.org/", StringComparison.Ordinal))
|
||||
outs.Add(new($"Codeberg ({trimmedUrl.Substring(21)})", $"{url}/commit/"));
|
||||
outs.Add(new($"Codeberg ({trimmedUrl.Slice(21)})", $"{url}/commit/"));
|
||||
else if (url.StartsWith("https://gitea.org/", StringComparison.Ordinal))
|
||||
outs.Add(new($"Gitea ({trimmedUrl.Substring(18)})", $"{url}/commit/"));
|
||||
outs.Add(new($"Gitea ({trimmedUrl.Slice(18)})", $"{url}/commit/"));
|
||||
else if (url.StartsWith("https://git.sr.ht/", StringComparison.Ordinal))
|
||||
outs.Add(new($"sourcehut ({trimmedUrl.Substring(18)})", $"{url}/commit/"));
|
||||
outs.Add(new($"sourcehut ({trimmedUrl.Slice(18)})", $"{url}/commit/"));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
|
@ -344,28 +344,28 @@ namespace SourceGit.Models
|
|||
if (filter.Mode == FilterMode.Included)
|
||||
includedRefs.Add(filter.Pattern);
|
||||
else if (filter.Mode == FilterMode.Excluded)
|
||||
excludedBranches.Add($"--exclude=\"{filter.Pattern.Substring(11)}\" --decorate-refs-exclude=\"{filter.Pattern}\"");
|
||||
excludedBranches.Add($"--exclude=\"{filter.Pattern.AsSpan().Slice(11)}\" --decorate-refs-exclude=\"{filter.Pattern}\"");
|
||||
}
|
||||
else if (filter.Type == FilterType.LocalBranchFolder)
|
||||
{
|
||||
if (filter.Mode == FilterMode.Included)
|
||||
includedRefs.Add($"--branches={filter.Pattern.Substring(11)}/*");
|
||||
includedRefs.Add($"--branches={filter.Pattern.AsSpan().Slice(11)}/*");
|
||||
else if (filter.Mode == FilterMode.Excluded)
|
||||
excludedBranches.Add($"--exclude=\"{filter.Pattern.Substring(11)}/*\" --decorate-refs-exclude=\"{filter.Pattern}/*\"");
|
||||
excludedBranches.Add($"--exclude=\"{filter.Pattern.AsSpan().Slice(11)}/*\" --decorate-refs-exclude=\"{filter.Pattern}/*\"");
|
||||
}
|
||||
else if (filter.Type == FilterType.RemoteBranch)
|
||||
{
|
||||
if (filter.Mode == FilterMode.Included)
|
||||
includedRefs.Add(filter.Pattern);
|
||||
else if (filter.Mode == FilterMode.Excluded)
|
||||
excludedRemotes.Add($"--exclude=\"{filter.Pattern.Substring(13)}\" --decorate-refs-exclude=\"{filter.Pattern}\"");
|
||||
excludedRemotes.Add($"--exclude=\"{filter.Pattern.AsSpan().Slice(13)}\" --decorate-refs-exclude=\"{filter.Pattern}\"");
|
||||
}
|
||||
else if (filter.Type == FilterType.RemoteBranchFolder)
|
||||
{
|
||||
if (filter.Mode == FilterMode.Included)
|
||||
includedRefs.Add($"--remotes={filter.Pattern.Substring(13)}/*");
|
||||
includedRefs.Add($"--remotes={filter.Pattern.AsSpan().Slice(13)}/*");
|
||||
else if (filter.Mode == FilterMode.Excluded)
|
||||
excludedRemotes.Add($"--exclude=\"{filter.Pattern.Substring(13)}/*\" --decorate-refs-exclude=\"{filter.Pattern}/*\"");
|
||||
excludedRemotes.Add($"--exclude=\"{filter.Pattern.AsSpan().Slice(13)}/*\" --decorate-refs-exclude=\"{filter.Pattern}/*\"");
|
||||
}
|
||||
else if (filter.Type == FilterType.Tag)
|
||||
{
|
||||
|
|
|
@ -1502,7 +1502,7 @@ namespace SourceGit.Views
|
|||
{
|
||||
if (line.Content.Length > 10000)
|
||||
{
|
||||
builder.Append(line.Content.Substring(0, 1000));
|
||||
builder.Append(line.Content.AsSpan().Slice(0, 1000));
|
||||
builder.Append($"...({line.Content.Length - 1000} characters trimmed)");
|
||||
}
|
||||
else
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue