Skip to content

Commit

Permalink
Allow MemoryPool.Shared devirtualization (dotnet/corefx#33085)
Browse files Browse the repository at this point in the history
Commit migrated from dotnet/corefx@c5cad0c
  • Loading branch information
benaadams authored and stephentoub committed Oct 27, 2018
1 parent aa97849 commit 30471ff
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/libraries/System.Memory/src/System/Buffers/MemoryPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ namespace System.Buffers
/// </summary>
public abstract class MemoryPool<T> : IDisposable
{
private static readonly MemoryPool<T> s_shared = new ArrayMemoryPool<T>();
// Store the shared ArrayMemoryPool 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.
//
// Roslyn proposal https://github.com/dotnet/roslyn/issues/30797 where field initalizer,
// backing field and property could be combined via `{ get } = ` to support devirtualization
// by having the auto-backing field be created as the derived type rather than the exposed type.
private static readonly ArrayMemoryPool<T> s_shared = new ArrayMemoryPool<T>();

/// <summary>
/// Returns a singleton instance of a MemoryPool based on arrays.
Expand Down

0 comments on commit 30471ff

Please sign in to comment.