diff --git a/1.6/Assemblies/1Fishery.dll b/1.6/Assemblies/1Fishery.dll index b8f0ecc..61fb43c 100644 Binary files a/1.6/Assemblies/1Fishery.dll and b/1.6/Assemblies/1Fishery.dll differ diff --git a/1.6/Assemblies/1Fishery.pdb b/1.6/Assemblies/1Fishery.pdb index 9d7281d..acf7402 100644 Binary files a/1.6/Assemblies/1Fishery.pdb and b/1.6/Assemblies/1Fishery.pdb differ diff --git a/Source/FisheryLib/FunctionPointers/MethodFactory.cs b/Source/FisheryLib/FunctionPointers/MethodFactory.cs index 161c168..b05a3b8 100644 --- a/Source/FisheryLib/FunctionPointers/MethodFactory.cs +++ b/Source/FisheryLib/FunctionPointers/MethodFactory.cs @@ -7,7 +7,9 @@ using System.Collections.Concurrent; using System.Diagnostics; using System.Linq; using System.Reflection.Emit; +using System.Runtime.CompilerServices; using System.Security; +using Verse; namespace FisheryLib.FunctionPointers; @@ -64,12 +66,18 @@ public abstract class MethodFactory(MethodInfo[] methods, string namePrefix, boo => type.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.DeclaredOnly) .Where(predicate).ToArray(); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + protected static bool UseReferenceIdentity(Type type) + => !type.IsValueType && typeof(Thing).IsAssignableFrom(type); + public new class Equals(Type type, string dynamicMethodNamePrefix, bool byRef) : MethodFactory(GetMethodInfoArraySafely(type), dynamicMethodNamePrefix, byRef) { protected override MethodInfo GetOrMakeMethodForType(Type type) => GetSpecializedMethod(type) - ?? (type.IsAssignableTo(typeof(IEquatable<>), type) + ?? (UseReferenceIdentity(type) + ? GetGeneric(nameof(FunctionPointers.Equals.Methods.Reference), type) + : type.IsAssignableTo(typeof(IEquatable<>), type) ? GetGeneric(type.IsValueType ? nameof(FunctionPointers.Equals.Methods.EquatableValueType) : nameof(FunctionPointers.Equals.Methods.EquatableReferenceType), type) @@ -235,7 +243,9 @@ public abstract class MethodFactory(MethodInfo[] methods, string namePrefix, boo { protected override MethodInfo GetOrMakeMethodForType(Type type) => GetSpecializedMethod(type) - ?? (type.IsNullable(out var genericArgument) + ?? (UseReferenceIdentity(type) + ? GetGeneric(nameof(FunctionPointers.GetHashCode.Methods.Reference), type) + : type.IsNullable(out var genericArgument) && genericArgument.IsAssignableTo(typeof(IEquatable<>), genericArgument) ? GetGeneric(nameof(FunctionPointers.GetHashCode.Methods.Nullable), genericArgument) : type.IsEnum @@ -375,4 +385,4 @@ public abstract class MethodFactory(MethodInfo[] methods, string namePrefix, boo private delegate int ByRefHashCodeGetter(ref T arg); private delegate int HashCodeGetter(T arg); } -} \ No newline at end of file +}