From 9d159eceee051b9536a26467adb489a6a5c0fa7a Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Wed, 2 Jan 2019 18:16:56 -0500 Subject: Use StringBuilderCache in PathInternal.NormalizeDirectorySeparators (#21760) When we do need to normalize, we're currently allocating the StringBuilder/char[] for the full path length. As long as the path length is less than the max cacheable size (360), we'll now use a cached builder. --- src/System.Private.CoreLib/shared/System/IO/PathInternal.Windows.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/System.Private.CoreLib/shared/System/IO/PathInternal.Windows.cs b/src/System.Private.CoreLib/shared/System/IO/PathInternal.Windows.cs index 5f9ee0e02d..ef6c131372 100644 --- a/src/System.Private.CoreLib/shared/System/IO/PathInternal.Windows.cs +++ b/src/System.Private.CoreLib/shared/System/IO/PathInternal.Windows.cs @@ -375,7 +375,7 @@ namespace System.IO if (normalized) return path; - StringBuilder builder = new StringBuilder(path.Length); + StringBuilder builder = StringBuilderCache.Acquire(path.Length); int start = 0; if (IsDirectorySeparator(path[start])) @@ -404,7 +404,7 @@ namespace System.IO builder.Append(current); } - return builder.ToString(); + return StringBuilderCache.GetStringAndRelease(builder); } /// -- cgit v1.2.3