Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 9b0ba41

Browse files
authored
Merge pull request #13907 from stephentoub/valuetask_astask_caching
Use AsyncTaskCache in ValueTask.AsTask()
2 parents bfbf47d + eb9bfb1 commit 9b0ba41

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/mscorlib/shared/System/Threading/Tasks/ValueTask.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public Task<TResult> AsTask() =>
114114
// Return the task if we were constructed from one, otherwise manufacture one. We don't
115115
// cache the generated task into _task as it would end up changing both equality comparison
116116
// and the hash code we generate in GetHashCode.
117-
_task ?? Task.FromResult(_result);
117+
_task ?? AsyncTaskMethodBuilder<TResult>.GetTaskForResult(_result);
118118

119119
/// <summary>Gets whether the <see cref="ValueTask{TResult}"/> represents a completed operation.</summary>
120120
public bool IsCompleted => _task == null || _task.IsCompleted;

src/mscorlib/src/System/Runtime/CompilerServices/AsyncMethodBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ internal void SetNotificationForWaitCompletion(bool enabled)
719719
/// <param name="result">The result for which we need a task.</param>
720720
/// <returns>The completed task containing the result.</returns>
721721
[MethodImpl(MethodImplOptions.AggressiveInlining)] // method looks long, but for a given TResult it results in a relatively small amount of asm
722-
private Task<TResult> GetTaskForResult(TResult result)
722+
internal static Task<TResult> GetTaskForResult(TResult result)
723723
{
724724
Contract.Ensures(
725725
EqualityComparer<TResult>.Default.Equals(result, Contract.Result<Task<TResult>>().Result),

0 commit comments

Comments
 (0)