From: Jan Kotas Date: Fri, 9 Mar 2018 20:45:12 +0000 (-0800) Subject: Use ValueStringBuilder instead of StringBuilderCache X-Git-Tag: accepted/tizen/unified/20190422.045933~2694 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=49f5dc0bf3f565ef13b7d2eed92c51fbb315932e;p=platform%2Fupstream%2Fcoreclr.git Use ValueStringBuilder instead of StringBuilderCache Signed-off-by: dotnet-bot-corefx-mirror --- diff --git a/src/mscorlib/shared/System/IO/PathInternal.cs b/src/mscorlib/shared/System/IO/PathInternal.cs index 789be91..059f0cf 100644 --- a/src/mscorlib/shared/System/IO/PathInternal.cs +++ b/src/mscorlib/shared/System/IO/PathInternal.cs @@ -119,13 +119,15 @@ namespace System.IO Debug.Assert(skip >= 0); bool flippedSeparator = false; + Span initialBuffer = stackalloc char[260 /* PathInternal.MaxShortPath */]; + ValueStringBuilder sb = new ValueStringBuilder(initialBuffer); + // Remove "//", "/./", and "/../" from the path by copying each character to the output, // except the ones we're removing, such that the builder contains the normalized path // at the end. - StringBuilder sb = StringBuilderCache.Acquire(path.Length); if (skip > 0) { - sb.Append(path, 0, skip); + sb.Append(path.AsSpan().Slice(0, skip)); } for (int i = skip; i < path.Length; i++) @@ -186,16 +188,14 @@ namespace System.IO sb.Append(c); } - if (flippedSeparator || sb.Length != path.Length) - { - return StringBuilderCache.GetStringAndRelease(sb); - } - else + // If we haven't changed the source path, return the original + if (!flippedSeparator && sb.Length == path.Length) { - // We haven't changed the source path, return the original - StringBuilderCache.Release(sb); + sb.Dispose(); return path; } + + return sb.ToString(); } } }