Created
September 22, 2017 02:47
-
-
Save SonicZentropy/e1b92c0a6de1ccbe95b7b7bf0d0746ee to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private Dictionary<ComponentTypesEnum, List<ComponentEcs>> _componentPools = | |
new Dictionary<ComponentTypes, List<ComponentEcs>>(new FastEnumIntEqualityComparer<ComponentTypes>()); // This is the custom comparator passed into the dict constructor | |
struct FastEnumIntEqualityComparer<TEnum> : IEqualityComparer<TEnum> | |
where TEnum : struct | |
{ | |
static class BoxAvoidance | |
{ | |
static readonly Func<TEnum, int> _wrapper; | |
public static int ToInt(TEnum enu) | |
{ | |
return _wrapper(enu); | |
} | |
static BoxAvoidance() | |
{ | |
var p = Expression.Parameter(typeof(TEnum), null); | |
var c = Expression.ConvertChecked(p, typeof(int)); | |
_wrapper = Expression.Lambda<Func<TEnum, int>>(c, p).Compile(); | |
} | |
} | |
public bool Equals(TEnum firstEnum, TEnum secondEnum) | |
{ | |
return BoxAvoidance.ToInt(firstEnum) == | |
BoxAvoidance.ToInt(secondEnum); | |
} | |
public int GetHashCode(TEnum firstEnum) | |
{ | |
return BoxAvoidance.ToInt(firstEnum); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment