From 199f7181c7042e25600d53bd3c401ba8ccab0da2 Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Tue, 26 Sep 2017 22:39:38 -0400 Subject: [PATCH] Merge pull request dotnet/coreclr#14178 from stephentoub/async_avoid_delegate Avoid async method delegate allocation Signed-off-by: dotnet-bot-corefx-mirror --- .../Runtime/CompilerServices/ConfiguredValueTaskAwaitable.cs | 5 ++++- .../System/Runtime/CompilerServices/ValueTaskAwaiter.cs | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Common/src/CoreLib/System/Runtime/CompilerServices/ConfiguredValueTaskAwaitable.cs b/src/Common/src/CoreLib/System/Runtime/CompilerServices/ConfiguredValueTaskAwaitable.cs index 4ec931c4af31..0784e6135c83 100644 --- a/src/Common/src/CoreLib/System/Runtime/CompilerServices/ConfiguredValueTaskAwaitable.cs +++ b/src/Common/src/CoreLib/System/Runtime/CompilerServices/ConfiguredValueTaskAwaitable.cs @@ -39,7 +39,7 @@ public struct ConfiguredValueTaskAwaiter : ICriticalNotifyCompletion /// The value being awaited. private ValueTask _value; // Methods are called on this; avoid making it readonly so as to avoid unnecessary copies /// The value to pass to ConfigureAwait. - private readonly bool _continueOnCapturedContext; + internal readonly bool _continueOnCapturedContext; /// Initializes the awaiter. /// The value to be awaited. @@ -66,6 +66,9 @@ public void OnCompleted(Action continuation) => /// Schedules the continuation action for the . public void UnsafeOnCompleted(Action continuation) => _value.AsTask().ConfigureAwait(_continueOnCapturedContext).GetAwaiter().UnsafeOnCompleted(continuation); + + /// Gets the task underlying . + internal Task AsTask() => _value.AsTask(); } } } diff --git a/src/Common/src/CoreLib/System/Runtime/CompilerServices/ValueTaskAwaiter.cs b/src/Common/src/CoreLib/System/Runtime/CompilerServices/ValueTaskAwaiter.cs index c4194825217a..30e688e07711 100644 --- a/src/Common/src/CoreLib/System/Runtime/CompilerServices/ValueTaskAwaiter.cs +++ b/src/Common/src/CoreLib/System/Runtime/CompilerServices/ValueTaskAwaiter.cs @@ -33,5 +33,8 @@ public void OnCompleted(Action continuation) => /// Schedules the continuation action for this ValueTask. public void UnsafeOnCompleted(Action continuation) => _value.AsTask().ConfigureAwait(continueOnCapturedContext: true).GetAwaiter().UnsafeOnCompleted(continuation); + + /// Gets the task underlying . + internal Task AsTask() => _value.AsTask(); } }