Extend Task.FromResult default task optimization to 16 byte unmanaged types (#87541)
authorStephen Toub <stoub@microsoft.com>
Thu, 15 Jun 2023 01:14:55 +0000 (21:14 -0400)
committerGitHub <noreply@github.com>
Thu, 15 Jun 2023 01:14:55 +0000 (21:14 -0400)
commit9a33ae78b81ffa50fcb1c87d2709e1e984866920
tree1360295376484be4d543d035785099a1526738ee
parent6800fd6ffe160236ef58e6eccc4fb2117b2ff179
Extend Task.FromResult default task optimization to 16 byte unmanaged types (#87541)

* Extend Task.FromResult default task optimization to 16 byte unmanaged types

For years, async methods / Task.FromResult has cached a `Task<T>` for `default(T)`, however it was only used when the result value was null.  Earlier in this release we extended that optimization to also use the default task when the value was 1, 2, 4, or 8 bytes (and not a reference type).  This extends that further to also handle types that are 16 bytes, so as to include types like Decimal, Guid, Int128, and DateTimeOffset.

* Fix tests to accomodate additional use of default cached task
src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs
src/libraries/System.Threading.Tasks/tests/System.Runtime.CompilerServices/AsyncTaskMethodBuilderTests.cs
src/libraries/System.Threading.Tasks/tests/Task/TaskRtTests.cs