Uh oh!
There was an error while loading. Please reload this page.
Add Enumerable.TryGetNonEnumeratedCount (Implements #27183) - #48239
Conversation
ghost
commented
Feb 12, 2021
Tagging subscribers to this area: @eiriktsarpalis Issue DetailsFix #27183.
|
ghost
commented
Feb 12, 2021
Note regarding the This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
stephentoub
left a comment
There was a problem hiding this comment.
Other than the build breaks, LGTM.
| { | ||
| int itemCount; | ||
| if (EnumerableHelpers.TryGetCount(items, out itemCount)) | ||
| if (System.Linq.Enumerable.TryGetNonEnumeratedCount(items, out itemCount)) |
There was a problem hiding this comment.
I wanted to avoid bringing all the enumerable methods into scope since this is a System.Collections namespace.
| /// The method is typically a constant-time operation, but ultimately this depends on the complexity | ||
| /// characteristics of the underlying collection implementation. | ||
| /// </remarks> | ||
| public static bool TryGetNonEnumeratedCount<TSource>(this IEnumerable<TSource> source, out int count) |
There was a problem hiding this comment.
This doesn't need to be generic? if it does, I think a non-generic overload would also make sense.
(roslyn is considering using this method as part of list pattern lowering, we probably don't want to skip it for IEnumerable see https://github.com/dotnet/csharplang/blob/master/meetings/2021/LDM-2021-02-03.md).
There was a problem hiding this comment.
We could do that, however it becomes more difficult to check for generic interfaces, which would require some form of reflection.
There was a problem hiding this comment.
which would require some form of reflection.
That's definitely a no-go because the point of using this is performance. Perhaps those generic interfaces need a non-generic base with Count prop. IMO TryGetNonEnumeratedCount shouldn't care about TSource.
eiriktsarpalis
commented
Feb 15, 2021
Linker test build failures seem unrelated to the change. |
Fix#27183.