Skip to content

Commit 481eab6

Browse files
Add a feature flag to not use GVM in Linq Select (#109978)
Adds a feature flag to allow Linq Select to not use a GVM implementation.
1 parent e7e8286 commit 481eab6

File tree

1 file changed

+13
-1
lines changed
  • src/libraries/System.Linq/src/System/Linq

1 file changed

+13
-1
lines changed

src/libraries/System.Linq/src/System/Linq/Select.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,19 @@ public static IEnumerable<TResult> Select<TSource, TResult>(
2525

2626
if (source is Iterator<TSource> iterator)
2727
{
28-
return iterator.Select(selector);
28+
// With native AOT, calling into the `Select` generic virtual method results in NxM
29+
// expansion of native code. If the option is enabled, we don't call the generic virtual
30+
// for value types. We don't do the same for reference types because reference type
31+
// expansion can happen lazily at runtime and the AOT compiler does postpone it (we
32+
// don't need more code, just more data structures describing the new types).
33+
if (IsSizeOptimized && typeof(TResult).IsValueType)
34+
{
35+
return new IEnumerableSelectIterator<TSource, TResult>(iterator, selector);
36+
}
37+
else
38+
{
39+
return iterator.Select(selector);
40+
}
2941
}
3042

3143
if (source is IList<TSource> ilist)

0 commit comments

Comments
 (0)