Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Allow MemoryPool.Shared devirtualization #33085

Merged
merged 1 commit into from
Oct 27, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/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