mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-21 04:04:59 +00:00
refactor: use String.AsSpan(int, int)
instead of String.AsSpan().Slice(int, int)
Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
parent
48bb8e91de
commit
825b74c2a3
12 changed files with 20 additions and 20 deletions
|
@ -105,7 +105,7 @@ namespace SourceGit.Commands
|
||||||
}
|
}
|
||||||
else if (line.StartsWith("-size ", StringComparison.Ordinal))
|
else if (line.StartsWith("-size ", StringComparison.Ordinal))
|
||||||
{
|
{
|
||||||
_result.LFSDiff.Old.Size = long.Parse(line.AsSpan().Slice(6));
|
_result.LFSDiff.Old.Size = long.Parse(line.AsSpan(6));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (ch == '+')
|
else if (ch == '+')
|
||||||
|
@ -116,12 +116,12 @@ namespace SourceGit.Commands
|
||||||
}
|
}
|
||||||
else if (line.StartsWith("+size ", StringComparison.Ordinal))
|
else if (line.StartsWith("+size ", StringComparison.Ordinal))
|
||||||
{
|
{
|
||||||
_result.LFSDiff.New.Size = long.Parse(line.AsSpan().Slice(6));
|
_result.LFSDiff.New.Size = long.Parse(line.AsSpan(6));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (line.StartsWith(" size ", StringComparison.Ordinal))
|
else if (line.StartsWith(" size ", StringComparison.Ordinal))
|
||||||
{
|
{
|
||||||
_result.LFSDiff.New.Size = _result.LFSDiff.Old.Size = long.Parse(line.AsSpan().Slice(6));
|
_result.LFSDiff.New.Size = _result.LFSDiff.Old.Size = long.Parse(line.AsSpan(6));
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,7 @@ namespace SourceGit.Commands
|
||||||
if (dateEndIdx == -1)
|
if (dateEndIdx == -1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var dateStr = line.AsSpan().Slice(0, dateEndIdx);
|
var dateStr = line.AsSpan(0, dateEndIdx);
|
||||||
if (double.TryParse(dateStr, out var date))
|
if (double.TryParse(dateStr, out var date))
|
||||||
statistics.AddCommit(line.Substring(dateEndIdx + 1), date);
|
statistics.AddCommit(line.Substring(dateEndIdx + 1), date);
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ namespace SourceGit.Converters
|
||||||
var home = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
|
var home = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
|
||||||
var prefixLen = home.EndsWith('/') ? home.Length - 1 : home.Length;
|
var prefixLen = home.EndsWith('/') ? home.Length - 1 : home.Length;
|
||||||
if (v.StartsWith(home, StringComparison.Ordinal))
|
if (v.StartsWith(home, StringComparison.Ordinal))
|
||||||
return $"~{v.AsSpan().Slice(prefixLen)}";
|
return $"~{v.AsSpan(prefixLen)}";
|
||||||
|
|
||||||
return v;
|
return v;
|
||||||
});
|
});
|
||||||
|
|
|
@ -196,7 +196,7 @@ namespace SourceGit.Models
|
||||||
private string GetEmailHash(string email)
|
private string GetEmailHash(string email)
|
||||||
{
|
{
|
||||||
var lowered = email.ToLower(CultureInfo.CurrentCulture).Trim();
|
var lowered = email.ToLower(CultureInfo.CurrentCulture).Trim();
|
||||||
var hash = MD5.HashData(Encoding.Default.GetBytes(lowered).AsSpan());
|
var hash = MD5.HashData(Encoding.Default.GetBytes(lowered));
|
||||||
var builder = new StringBuilder(hash.Length * 2);
|
var builder = new StringBuilder(hash.Length * 2);
|
||||||
foreach (var c in hash)
|
foreach (var c in hash)
|
||||||
builder.Append(c.ToString("x2"));
|
builder.Append(c.ToString("x2"));
|
||||||
|
|
|
@ -148,9 +148,9 @@ namespace SourceGit.Models
|
||||||
public void GenerateNewPatchFromSelection(Change change, string fileBlobGuid, TextDiffSelection selection, bool revert, string output)
|
public void GenerateNewPatchFromSelection(Change change, string fileBlobGuid, TextDiffSelection selection, bool revert, string output)
|
||||||
{
|
{
|
||||||
var isTracked = !string.IsNullOrEmpty(fileBlobGuid);
|
var isTracked = !string.IsNullOrEmpty(fileBlobGuid);
|
||||||
var fileGuid = isTracked ? fileBlobGuid.AsSpan().Slice(0, 8) : "00000000".AsSpan();
|
var fileGuid = isTracked ? fileBlobGuid : "00000000";
|
||||||
|
|
||||||
var builder = new StringBuilder(512);
|
var builder = new StringBuilder();
|
||||||
builder.Append("diff --git a/").Append(change.Path).Append(" b/").Append(change.Path).Append('\n');
|
builder.Append("diff --git a/").Append(change.Path).Append(" b/").Append(change.Path).Append('\n');
|
||||||
if (!revert && !isTracked)
|
if (!revert && !isTracked)
|
||||||
builder.Append("new file mode 100644\n");
|
builder.Append("new file mode 100644\n");
|
||||||
|
|
|
@ -23,7 +23,7 @@ namespace SourceGit.Models
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (IsDetached)
|
if (IsDetached)
|
||||||
return $"deteched HEAD at {Head.AsSpan().Slice(10)}";
|
return $"deteched HEAD at {Head.AsSpan(10)}";
|
||||||
|
|
||||||
if (Branch.StartsWith("refs/heads/", StringComparison.Ordinal))
|
if (Branch.StartsWith("refs/heads/", StringComparison.Ordinal))
|
||||||
return Branch.Substring(11);
|
return Branch.Substring(11);
|
||||||
|
|
|
@ -32,7 +32,7 @@ namespace SourceGit.ViewModels
|
||||||
{
|
{
|
||||||
_repo = repo;
|
_repo = repo;
|
||||||
_revision = commit.SHA;
|
_revision = commit.SHA;
|
||||||
_saveFile = $"archive-{commit.SHA.AsSpan().Slice(0, 10)}.zip";
|
_saveFile = $"archive-{commit.SHA.AsSpan(0, 10)}.zip";
|
||||||
BasedOn = commit;
|
BasedOn = commit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ namespace SourceGit.ViewModels
|
||||||
{
|
{
|
||||||
_repo = repo;
|
_repo = repo;
|
||||||
|
|
||||||
Title = $"{file} @ {revision.AsSpan().Slice(0, 10)}";
|
Title = $"{file} @ {revision.AsSpan(0, 10)}";
|
||||||
Task.Run(() =>
|
Task.Run(() =>
|
||||||
{
|
{
|
||||||
var result = new Commands.Blame(repo, file, revision).Result();
|
var result = new Commands.Blame(repo, file, revision).Result();
|
||||||
|
|
|
@ -584,7 +584,7 @@ namespace SourceGit.ViewModels
|
||||||
var home = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
|
var home = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
|
||||||
var prefixLen = home.EndsWith('/') ? home.Length - 1 : home.Length;
|
var prefixLen = home.EndsWith('/') ? home.Length - 1 : home.Length;
|
||||||
if (path.StartsWith(home, StringComparison.Ordinal))
|
if (path.StartsWith(home, StringComparison.Ordinal))
|
||||||
path = $"~{path.AsSpan().Slice(prefixLen)}";
|
path = $"~{path.AsSpan(prefixLen)}";
|
||||||
}
|
}
|
||||||
|
|
||||||
Title = $"[{workspace}] {name} ({path})";
|
Title = $"[{workspace}] {name} ({path})";
|
||||||
|
|
|
@ -635,7 +635,7 @@ namespace SourceGit.ViewModels
|
||||||
}
|
}
|
||||||
else if (_inProgressContext is RevertInProgress revert)
|
else if (_inProgressContext is RevertInProgress revert)
|
||||||
{
|
{
|
||||||
useTheirs.Header = App.Text("FileCM.ResolveUsing", $"{revert.Head.SHA.AsSpan().Slice(0, 10)} (revert)");
|
useTheirs.Header = App.Text("FileCM.ResolveUsing", $"{revert.Head.SHA.AsSpan(0, 10)} (revert)");
|
||||||
useMine.Header = App.Text("FileCM.ResolveUsing", _repo.CurrentBranch.Name);
|
useMine.Header = App.Text("FileCM.ResolveUsing", _repo.CurrentBranch.Name);
|
||||||
}
|
}
|
||||||
else if (_inProgressContext is MergeInProgress merge)
|
else if (_inProgressContext is MergeInProgress merge)
|
||||||
|
@ -993,7 +993,7 @@ namespace SourceGit.ViewModels
|
||||||
}
|
}
|
||||||
else if (_inProgressContext is RevertInProgress revert)
|
else if (_inProgressContext is RevertInProgress revert)
|
||||||
{
|
{
|
||||||
useTheirs.Header = App.Text("FileCM.ResolveUsing", $"{revert.Head.SHA.AsSpan().Slice(0, 10)} (revert)");
|
useTheirs.Header = App.Text("FileCM.ResolveUsing", $"{revert.Head.SHA.AsSpan(0, 10)} (revert)");
|
||||||
useMine.Header = App.Text("FileCM.ResolveUsing", _repo.CurrentBranch.Name);
|
useMine.Header = App.Text("FileCM.ResolveUsing", _repo.CurrentBranch.Name);
|
||||||
}
|
}
|
||||||
else if (_inProgressContext is MergeInProgress merge)
|
else if (_inProgressContext is MergeInProgress merge)
|
||||||
|
@ -1417,7 +1417,7 @@ namespace SourceGit.ViewModels
|
||||||
var home = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
|
var home = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
|
||||||
var prefixLen = home.EndsWith('/') ? home.Length - 1 : home.Length;
|
var prefixLen = home.EndsWith('/') ? home.Length - 1 : home.Length;
|
||||||
if (gitTemplate.StartsWith(home, StringComparison.Ordinal))
|
if (gitTemplate.StartsWith(home, StringComparison.Ordinal))
|
||||||
friendlyName = $"~{gitTemplate.AsSpan().Slice(prefixLen)}";
|
friendlyName = $"~{gitTemplate.AsSpan(prefixLen)}";
|
||||||
}
|
}
|
||||||
|
|
||||||
var gitTemplateItem = new MenuItem();
|
var gitTemplateItem = new MenuItem();
|
||||||
|
|
|
@ -205,7 +205,7 @@ namespace SourceGit.Views
|
||||||
foreach (var item in selected)
|
foreach (var item in selected)
|
||||||
{
|
{
|
||||||
if (item is Models.Commit commit)
|
if (item is Models.Commit commit)
|
||||||
builder.AppendLine($"{commit.SHA.AsSpan().Slice(0, 10)} - {commit.Subject}");
|
builder.AppendLine($"{commit.SHA.AsSpan(0, 10)} - {commit.Subject}");
|
||||||
}
|
}
|
||||||
|
|
||||||
App.CopyText(builder.ToString());
|
App.CopyText(builder.ToString());
|
||||||
|
|
|
@ -1047,7 +1047,7 @@ namespace SourceGit.Views
|
||||||
// The first selected line (partial selection)
|
// The first selected line (partial selection)
|
||||||
if (i == startIdx && startPosition.Column > 1)
|
if (i == startIdx && startPosition.Column > 1)
|
||||||
{
|
{
|
||||||
builder.Append(line.Content.AsSpan().Slice(startPosition.Column - 1));
|
builder.Append(line.Content.AsSpan(startPosition.Column - 1));
|
||||||
builder.Append(Environment.NewLine);
|
builder.Append(Environment.NewLine);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -1064,7 +1064,7 @@ namespace SourceGit.Views
|
||||||
{
|
{
|
||||||
if (endPosition.Column - 1 < line.Content.Length)
|
if (endPosition.Column - 1 < line.Content.Length)
|
||||||
{
|
{
|
||||||
builder.Append(line.Content.AsSpan().Slice(0, endPosition.Column - 1));
|
builder.Append(line.Content.AsSpan(0, endPosition.Column - 1));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1254,12 +1254,12 @@ namespace SourceGit.Views
|
||||||
var textDiff = DataContext as Models.TextDiff;
|
var textDiff = DataContext as Models.TextDiff;
|
||||||
if (textDiff != null)
|
if (textDiff != null)
|
||||||
{
|
{
|
||||||
var builder = new StringBuilder(512);
|
var builder = new StringBuilder();
|
||||||
foreach (var line in textDiff.Lines)
|
foreach (var line in textDiff.Lines)
|
||||||
{
|
{
|
||||||
if (line.Content.Length > 10000)
|
if (line.Content.Length > 10000)
|
||||||
{
|
{
|
||||||
builder.Append(line.Content.AsSpan().Slice(0, 1000));
|
builder.Append(line.Content.AsSpan(0, 1000));
|
||||||
builder.Append($"...({line.Content.Length - 1000} character trimmed)");
|
builder.Append($"...({line.Content.Length - 1000} character trimmed)");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue