Special-case T==char in string.Concat(IEnumerable<T>)
authorStephen Toub <stoub@microsoft.com>
Tue, 3 Oct 2017 15:29:06 +0000 (11:29 -0400)
committerStephen Toub <stoub@microsoft.com>
Tue, 3 Oct 2017 15:29:06 +0000 (11:29 -0400)
commit5236ffd6679b3380327fd43cbc4fdfca208a0edd
tree5c62804b121b7c5f95711e0955201ec1b03ad10a
parentb5d08755c552961640df581ff532e87d187a4be3
Special-case T==char in string.Concat(IEnumerable<T>)

This allows string.Concat to be used as an efficient mechanism for creating a `string` from an `IEnumerable<char>`.  The JIT specializes the implementation for char vs non-char, so there's minimal impact on the non-char case, and for the char case, we a) avoid creating a string for each individual char, and b) use StringBuilder's fast path for adding individual chars.  This can result in a massive allocation savings for long enumerations (for <= 1 char, there's no difference, but each character after that is an allocation saved), and for more than a few characters can yield up to a 2x increase in throughput.
src/mscorlib/src/System/String.Manipulation.cs