-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
1 parent
d29c1c5
commit 9bda919
Showing
3 changed files
with
128 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.