diff options
author | Stephen Toub <stoub@microsoft.com> | 2019-01-02 18:16:56 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-02 18:16:56 -0500 |
commit | 9d159eceee051b9536a26467adb489a6a5c0fa7a (patch) | |
tree | f24b0990b9e30e01a2fd55b199e7eeefcd747107 | |
parent | e2a576a7130978dfeca4c100868789eee4adc403 (diff) | |
download | coreclr-9d159eceee051b9536a26467adb489a6a5c0fa7a.tar.gz coreclr-9d159eceee051b9536a26467adb489a6a5c0fa7a.tar.bz2 coreclr-9d159eceee051b9536a26467adb489a6a5c0fa7a.zip |
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.
-rw-r--r-- | src/System.Private.CoreLib/shared/System/IO/PathInternal.Windows.cs | 4 |
1 files 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); } /// <summary> |