A few more Enum perf improvements (#21284)
authorStephen Toub <stoub@microsoft.com>
Fri, 30 Nov 2018 15:16:25 +0000 (10:16 -0500)
committerGitHub <noreply@github.com>
Fri, 30 Nov 2018 15:16:25 +0000 (10:16 -0500)
commit7972722e3a3788fe96056d0a5398f90466588b8f
tree18ac859e560597c906fa8ec150582f63e9235075
parent2af1774e2b054044721d5bbca0ef668de19b3cc3
A few more Enum perf improvements (#21284)

* A few more Enum perf improvements

I started out to just remove the unnecessary boxing allocation that happens when you do enum.ToString("D") or, if the value doesn't map to a named enum entry, just enum.ToString() (there's an internal boxing of the value that happens in addition to any boxing that happens of the enum itself).  As part of that, I added a ValueToString method that replaces the GetValue().ToString() calls that appear several times, and in writing that ValueToString, I opted to avoid pinning, instead using Unsafe.As.  Once I did that, I then removed pinning everywhere else it was being done, standardizing on Unsafe.As.

* Address PR feedback
src/System.Private.CoreLib/ILLinkTrim.xml
src/System.Private.CoreLib/src/System/Enum.cs
src/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilder.cs
src/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.cs
src/System.Private.CoreLib/src/System/Runtime/CompilerServices/jithelpers.cs
src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/CLRIPropertyValueImpl.cs