1.6 to main #1
Binary file not shown.
Binary file not shown.
@@ -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<T>(ref T arg);
|
||||
private delegate int HashCodeGetter<in T>(T arg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user