Reduce allocations in string.ToLower/ToUpper on Unix
authorstephentoub <stoub@microsoft.com>
Thu, 8 Oct 2015 15:51:14 +0000 (11:51 -0400)
committerstephentoub <stoub@microsoft.com>
Thu, 8 Oct 2015 15:51:14 +0000 (11:51 -0400)
commitfbdbfa1241139848a38c66d2d3313529b30fc8b8
tree71d4c2c24a546c3df88ed5b41b4958a81a5fa264
parent3e82c94cafb35cef213665153ae59058b31dc368
Reduce allocations in string.ToLower/ToUpper on Unix

On Windows, ToLower/ToUpper calls into InternalChangeCaseString in the runtime which does two optiizations:
- a 0-length check to just return an empty string if the source is empty
- allocates the string and writes the results into it directly

In our current Unix implementation, the ChangeCase implementation doesn't do either of these, no special-casing empty strings and first allocating a char[] into which the results are written and then constructing a string from that.

This commit brings the Unix implementation more in line with the Windows one, adding the 0-length check, and writing the results directly into the result string so as to avoid the unnecessary char[] allocation and copy.
src/mscorlib/corefx/System/Globalization/TextInfo.Unix.cs