diff --git a/src/MarkdownSnippets/SnippetExtensions.cs b/src/MarkdownSnippets/SnippetExtensions.cs index 99cfc19f..73892394 100644 --- a/src/MarkdownSnippets/SnippetExtensions.cs +++ b/src/MarkdownSnippets/SnippetExtensions.cs @@ -15,15 +15,22 @@ public static Dictionary> ToDictionary(this IEnum return null; } - var builder = StringBuilderCache.Acquire(path.Length); - foreach (var ch in path) + var count = path.Count(_ => _ is '/' or '\\'); + if (count == 0) { - if (ch is not ('/' or '\\')) - { - builder.Append(ch); - } + return path; } - return StringBuilderCache.GetStringAndRelease(builder); + return string.Create(path.Length - count, path, (span, source) => + { + var index = 0; + foreach (var ch in source) + { + if (ch is not ('/' or '\\')) + { + span[index++] = ch; + } + } + }); } -} \ No newline at end of file +}