Skip to content

Commit

Permalink
Allow ArrayPool.Shared devirtualization (redux) (dotnet#20637)
Browse files Browse the repository at this point in the history
  • Loading branch information
benaadams authored and A-And committed Nov 20, 2018
1 parent 8c0d260 commit f10ab43
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ namespace System.Buffers
/// </remarks>
public abstract class ArrayPool<T>
{
// Store the shared ArrayPool in a field of its derived sealed type so the Jit can "see" the exact type
// when the Shared property is inlined which will allow it to devirtualize calls made on it.
private readonly static TlsOverPerCoreLockedStacksArrayPool<T> s_shared = new TlsOverPerCoreLockedStacksArrayPool<T>();

/// <summary>
/// Retrieves a shared <see cref="ArrayPool{T}"/> instance.
/// </summary>
Expand All @@ -33,7 +37,7 @@ public abstract class ArrayPool<T>
/// optimized for very fast access speeds, at the expense of more memory consumption.
/// The shared pool instance is created lazily on first access.
/// </remarks>
public static ArrayPool<T> Shared { get; } = new TlsOverPerCoreLockedStacksArrayPool<T>();
public static ArrayPool<T> Shared => s_shared;

/// <summary>
/// Creates a new <see cref="ArrayPool{T}"/> instance using default configuration options.
Expand Down

0 comments on commit f10ab43

Please sign in to comment.