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.
Commit migrated from https://github.com/dotnet/coreclr/commit/
fbdbfa1241139848a38c66d2d3313529b30fc8b8