You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Dedup Task.WhenAll non-generic and generic implementations (#88154)
The generic implementation was calling the non-generic one and then using an additional continuation to extract the resulting `Task<TResult>` due to lack of covariance on classes. We can instead just factor the shared implementation out into a generic with the type parameter constrained to be a Task. This results in simpler code as well as avoiding an extra continuation in the generic case.
As part of cleaning this up:
- I changed code where we need to make a defensive copy of an input collection to use CopyTo; we were already doing this in some places but not others. This saves on an enumerator allocation when enumerating the source collection, as well as multiple interface calls.
- I augmented WhenAny to also special-case `List<Task>`, as that's a common input and we can handle it a bit more efficiently, especially if the collection ends up containing just two tasks.
- I removed the `GenericDelegateCache<TAntecedentResult, TResult>`. That was from a time before the C# compiler supported caching of generic lambdas. It would have needed to have been updated to handle the stronger type coming out of CommonCWAnyLogic, so I instead just got rid of it. We're better off lazily-creating these rarely used delegates, anyway.
0 commit comments