use reference identity for Thing and fix ListerBuildings type cache fallbacks, possibly fixed rgctx bug

This commit is contained in:
localavaster
2026-04-15 10:10:50 -06:00
parent 124052be77
commit 50f4d5378b
3 changed files with 13 additions and 3 deletions
@@ -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);
}
}
}