From 979b8f9da6186c84efacae5c49c465ca48569e52 Mon Sep 17 00:00:00 2001 From: qiufengshe <172344058@qq.com> Date: Sat, 19 Apr 2025 15:32:10 +0800 Subject: [PATCH 1/2] minimize temporary strings for better performance --- src/Commands/Statistics.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Commands/Statistics.cs b/src/Commands/Statistics.cs index 41b3889eb..ea0b86de4 100644 --- a/src/Commands/Statistics.cs +++ b/src/Commands/Statistics.cs @@ -1,4 +1,4 @@ -using System; +using System; namespace SourceGit.Commands { @@ -40,7 +40,7 @@ private void ParseLine(Models.Statistics statistics, string line) if (dateEndIdx == -1) return; - var dateStr = line.Substring(0, dateEndIdx); + var dateStr = line.AsSpan().Slice(0, dateEndIdx); if (double.TryParse(dateStr, out var date)) statistics.AddCommit(line.Substring(dateEndIdx + 1), date); } From c99131d1cb1f57fce7c17fe73e399d59593a9f19 Mon Sep 17 00:00:00 2001 From: qiufengshe <172344058@qq.com> Date: Mon, 21 Apr 2025 21:37:23 +0800 Subject: [PATCH 2/2] minimize temporary strings for better performance --- src/Commands/Diff.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Commands/Diff.cs b/src/Commands/Diff.cs index 65a2a6f53..8df8cbaa2 100644 --- a/src/Commands/Diff.cs +++ b/src/Commands/Diff.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Text.RegularExpressions; @@ -103,7 +103,7 @@ private void ParseLine(string line) } else if (line.StartsWith("-size ", StringComparison.Ordinal)) { - _result.LFSDiff.Old.Size = long.Parse(line.Substring(6)); + _result.LFSDiff.Old.Size = long.Parse(line.AsSpan().Slice(6)); } } else if (ch == '+') @@ -114,12 +114,12 @@ private void ParseLine(string line) } else if (line.StartsWith("+size ", StringComparison.Ordinal)) { - _result.LFSDiff.New.Size = long.Parse(line.Substring(6)); + _result.LFSDiff.New.Size = long.Parse(line.AsSpan().Slice(6)); } } else if (line.StartsWith(" size ", StringComparison.Ordinal)) { - _result.LFSDiff.New.Size = _result.LFSDiff.Old.Size = long.Parse(line.Substring(6)); + _result.LFSDiff.New.Size = _result.LFSDiff.Old.Size = long.Parse(line.AsSpan().Slice(6)); } return; }