-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
IReadOnlyCollection<T> does not implement ICollection<T> #33245
Conversation
@stephentoub Does the order of these checks matter? |
Just having the check itself matters. We've rejected this same change multiple times in the past, as it adds overhead to the common non-collection path and it's relatively rare to have IReadOnlyCollection types that aren't also ICollection. It's possible things have changed perf-wise with @VSadov's recent casting work, but justifying this would need new numbers. |
Cost of checking for So - yes, it is no longer a special expensive cast, but not free either. Basically it is just another type check that needs to be amortized by potential benefits. |
@@ -20,6 +20,10 @@ public static bool Any<TSource>(this IEnumerable<TSource> source) | |||
{ | |||
return collectionoft.Count != 0; | |||
} | |||
|
|||
if (source is IReadOnlyCollection<TSource> readOnlyCollection) | |||
return readOnlyCollection.Count != 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use curly braces
There are ~20 places across the System.Linq implementation today where we check for |
No description provided.