dotnet/corefx — pull request #90 by stephentoub (2014-11-14 18:53:43+00:00)
Title: Add ImmutableArrayExtensions.SelectMany extension method

For C# query comprehensions of the form:

from i in immutableArray
from j in someOtherCollection
select Something(i, j)

the compiler requires a particular signature of SelectMany. This method isn't provided today by ImmutableArrayExtensions for ImmutableArray, and thus the compiler binds to Enumerable's corresponding SelectMany implementation. This results in a few more allocations than are truly needed: first, the ImmutableArray needs to be boxed when passed as an IEnumerable, and second, when SelectMany's iterator then enumerates this IEnumerable, ImmutableArray's IEnumerable.GetEnumerator allocates an EnumeratorObject to server as the enumerator.

This PR provides an ImmutableArrayExtensions.SelectMany method that avoids these two allocations. It includes tests as well.