Commit 77f04cd 1 parent 7d16acf commit 77f04cd Copy full SHA for 77f04cd
File tree 1 file changed +9
-2
lines changed
1 file changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -43,16 +43,23 @@ public MethodPassResult Run(MethodTransformContext ctx)
43
43
44
44
private static bool IsProfitableToExpand ( LinqSourceNode source , LinqSink sink )
45
45
{
46
- //Unfiltered Count()/Any() is not profitable because we scan the entire source.
46
+ //Unfiltered Count()/Any() is not profitable because we always scan over
47
+ //the entire source, and LINQ specializes over collections and such.
47
48
if ( sink . SubjectCall is { NumArgs : 1 , Method . Name : "Count" or "Any" } ) {
48
49
return false ;
49
50
}
50
- //Concretizing enumerator sources may not be profitable because
51
+ //Expanding enumerator sources may not be profitable because
51
52
//Linq can special-case source types and defer to e.g. Array.Copy().
52
53
//Similarly, expanding an enumerator source to a loop sink is an expansive no-op.
53
54
if ( source is EnumeratorSource && source . Drain == sink ) {
54
55
return sink is not ( ConcretizationSink or LoopSink ) ;
55
56
}
57
+ //Range().ToArray() and ToList() are already special-cased by LINQ, and vectorized in .NET 8.
58
+ // - https://github.com/dubiousconst282/DistIL/issues/25
59
+ // - https://github.com/dotnet/runtime/pull/87992
60
+ if ( source is IntRangeSource && source . Drain == sink ) {
61
+ return sink is not ListOrArraySink ;
62
+ }
56
63
return true ;
57
64
}
58
65
You can’t perform that action at this time.
0 commit comments