Separated out from dotnet/corefx#12703. Relevant discussion: dotnet/corefx#12703 (comment)
tl;dr We may want to put a part of Enumerable.Count<T> in a non-generic method so that the JIT has less code to generate during the following 2 scenarios:
-
For a particular value type T, the source enumerable always implements ICollection, IIListProvider, etc. and we can determine the count without actually enumerating
-
We fall back to iterating manually over the enumerable for at least 2 different value types
More details can be found in the comment linked to. Opening this as a tracking issue.
Separated out from dotnet/corefx#12703. Relevant discussion: dotnet/corefx#12703 (comment)
tl;dr We may want to put a part of
Enumerable.Count<T>in a non-generic method so that the JIT has less code to generate during the following 2 scenarios:For a particular value type T, the source enumerable always implements
ICollection,IIListProvider, etc. and we can determine the count without actually enumeratingWe fall back to iterating manually over the enumerable for at least 2 different value types
More details can be found in the comment linked to. Opening this as a tracking issue.