Change our cached task to a field

This makes it more inlinable and saves a volatile lookup on netstandard.
This commit is contained in:
Ryan Nowak 2016-05-11 18:07:46 -07:00
parent 04ffc4d2eb
commit fb5d92bdc0
1 changed files with 9 additions and 14 deletions

View File

@ -7,23 +7,18 @@ namespace Microsoft.AspNetCore.Mvc.Internal
{ {
public static class TaskCache public static class TaskCache
{ {
#if NET451
static readonly Task _completedTask = Task.FromResult(0);
#endif
/// <summary>Gets a task that's already been completed successfully.</summary> /// <summary>
/// <remarks>May not always return the same instance.</remarks> /// A <see cref="Task"/> that's already completed successfully.
public static Task CompletedTask /// </summary>
{ /// <remarks>
get /// We're caching this in a static readonly field to make it more inlinable and avoid the volatile lookup done
{ /// by <c>Task.CompletedTask</c>.
/// </remarks>
#if NET451 #if NET451
return _completedTask; public static readonly Task CompletedTask = Task.FromResult(0);
#else #else
return Task.CompletedTask; public static readonly Task CompletedTask = Task.CompletedTask;
#endif #endif
}
}
} }
} }