Streamline default EqualityComparer and Comparer for Enums (#21604)
authorJan Kotas <jkotas@microsoft.com>
Fri, 21 Dec 2018 17:25:24 +0000 (09:25 -0800)
committerGitHub <noreply@github.com>
Fri, 21 Dec 2018 17:25:24 +0000 (09:25 -0800)
commit82e02f37564f83c3a7c90e5e28a652a39017701a
tree3df12a74b2c4667afbb17f011c03a8266fda191a
parent63ab188ccae6cc1b0c65103db7f453833e2c19a8
Streamline default EqualityComparer and Comparer for Enums (#21604)

This borrows the implementation strategy for these from CoreRT. It makes it both simpler (fewer types and lines of code) and faster in some cases since we always use the exact right underlying type.

E.g. The following micro-benchmark is 25% faster with this change:

```
enum MyEnum : byte { x, y };

var comparer = Comparer<MyEnum>.Default;

for (int i = 0; i < 100000000; i++)
{
    comparer.Compare(MyEnum.x, MyEnum.y);
    comparer.Compare(MyEnum.y, MyEnum.x);
}
```
src/System.Private.CoreLib/src/System/Collections/Generic/Comparer.cs
src/System.Private.CoreLib/src/System/Collections/Generic/ComparerHelpers.cs
src/System.Private.CoreLib/src/System/Collections/Generic/EqualityComparer.cs
src/System.Private.CoreLib/src/System/Runtime/CompilerServices/jithelpers.cs
src/vm/jitinterface.cpp
src/vm/mscorlib.h