diff --git a/src/mscorlib/shared/System/Buffers/ArrayPool.cs b/src/mscorlib/shared/System/Buffers/ArrayPool.cs index 77a07f7fa520..821927c7cbae 100644 --- a/src/mscorlib/shared/System/Buffers/ArrayPool.cs +++ b/src/mscorlib/shared/System/Buffers/ArrayPool.cs @@ -2,8 +2,18 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System.Runtime.CompilerServices; + namespace System.Buffers { + internal static class ArrayPools + { + private static TlsOverPerCoreLockedStacksArrayPool s_bytePool = new TlsOverPerCoreLockedStacksArrayPool(); + private static TlsOverPerCoreLockedStacksArrayPool s_charPool = new TlsOverPerCoreLockedStacksArrayPool(); + + internal static TlsOverPerCoreLockedStacksArrayPool BytePool => s_bytePool; + internal static TlsOverPerCoreLockedStacksArrayPool CharPool => s_charPool; + } /// /// Provides a resource pool that enables reusing instances of type . /// @@ -19,6 +29,7 @@ namespace System.Buffers /// public abstract class ArrayPool { + private static ConfigurableArrayPool s_generalPool = typeof(T) == typeof(byte) || typeof(T) == typeof(char) ? null : new ConfigurableArrayPool(); /// /// Retrieves a shared instance. /// @@ -33,9 +44,25 @@ public abstract class ArrayPool /// optimized for very fast access speeds, at the expense of more memory consumption. /// The shared pool instance is created lazily on first access. /// - public static ArrayPool Shared { get; } = - typeof(T) == typeof(byte) || typeof(T) == typeof(char) ? new TlsOverPerCoreLockedStacksArrayPool() : - Create(); + public static ArrayPool Shared + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get + { + if (typeof(T) == typeof(byte)) + { + return (ArrayPool)(object)ArrayPools.BytePool; + } + else if (typeof(T) == typeof(char)) + { + return (ArrayPool)(object)ArrayPools.CharPool; + } + else + { + return s_generalPool; + } + } + } /// /// Creates a new instance using default configuration options.