Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dedup Task.WhenAll non-generic and generic implementations #88154

Merged
merged 2 commits into from
Jul 5, 2023

Commits on Jun 28, 2023

  1. Dedup Task.WhenAll non-generic and generic implementations

    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.
    stephentoub committed Jun 28, 2023
    Configuration menu
    Copy the full SHA
    6fcd926 View commit details
    Browse the repository at this point in the history

Commits on Jun 30, 2023

  1. Configuration menu
    Copy the full SHA
    9e4aff5 View commit details
    Browse the repository at this point in the history