Improve Enum.ToString perf for [Flags] enums by stephentoub · Pull Request #21254 · dotnet/coreclr (original) (raw)
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.