Improve Enum.ToString perf for [Flags] enums (#21254)
authorStephen Toub <stoub@microsoft.com>
Thu, 29 Nov 2018 04:04:08 +0000 (23:04 -0500)
committerJan Kotas <jkotas@microsoft.com>
Thu, 29 Nov 2018 04:04:08 +0000 (20:04 -0800)
commiteffe7cafdb828fc90ec7bbd09ae8b3c259a76eb0
treebca10f836f966598e137c7f3ed5d1ef1aabe234d
parent63b23cff8a93f834c61555960cbd724ba2276376
Improve Enum.ToString perf for [Flags] enums (#21254)

Two main changes:
- Rather than using a StringBuilder to insert the strings for all of the consistuent values, we track the constituent values in a span, summing the expected length, and then new up a string and copy the results directly into it.
- When there's a single value that matches the supplied value, we just return the cached string rather than allocating a new one.
src/System.Private.CoreLib/src/System/Enum.cs