diff --git a/src/Verify/FileNameCleaner.cs b/src/Verify/FileNameCleaner.cs index ca39f5fc7d..69a3173ae3 100644 --- a/src/Verify/FileNameCleaner.cs +++ b/src/Verify/FileNameCleaner.cs @@ -60,20 +60,20 @@ public static string ReplaceInvalidFileNameChars(this string value) return value; } - var chars = value.ToCharArray(); - span[..index] - .CopyTo(chars); - chars[index] = '-'; + Span target = stackalloc char[value.Length]; + span.CopyTo(target); + + target[index] = '-'; index++; - for (; index < chars.Length; index++) + for (; index < target.Length; index++) { - if (IsInvalid(chars[index])) + if (IsInvalid(target[index])) { - chars[index] = '-'; + target[index] = '-'; } } - return new(chars); + return target.ToString(); } static int IndexOfInvalidChar(CharSpan span) => @@ -83,7 +83,6 @@ static int IndexOfInvalidChar(CharSpan span) => span.IndexOfAny(invalidFileNameChars.AsSpan()); #endif - static bool IsInvalid(char ch) => #if NET8_0_OR_GREATER invalidFileNameSearchValues.Contains(ch);