@@ -14,18 +14,30 @@ internal static unsafe partial class VirtualDispatchHelpers
1414{
1515 private struct VirtualResolutionData : IEquatable < VirtualResolutionData >
1616 {
17+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
18+ public VirtualResolutionData ( MethodTable * methodTable , IntPtr classHandleTargetMethod , IntPtr methodHandle )
19+ {
20+ HashCode = ( int ) ( ( uint ) methodTable + ( BitOperations . RotateLeft ( ( uint ) classHandleTargetMethod , 5 ) ) + ( BitOperations . RotateRight ( ( uint ) methodHandle , 5 ) ) ) ;
21+ MethodTable = methodTable ;
22+ ClassHandleTargetMethod = classHandleTargetMethod ;
23+ MethodHandle = methodHandle ;
24+ }
25+ public int HashCode ;
1726 public MethodTable * MethodTable ;
1827 public IntPtr ClassHandleTargetMethod ;
1928 public IntPtr MethodHandle ;
2029
30+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
2131 public bool Equals ( VirtualResolutionData other ) =>
32+ HashCode == other . HashCode &&
2233 MethodTable == other . MethodTable &&
2334 ClassHandleTargetMethod == other . ClassHandleTargetMethod &&
2435 MethodHandle == other . MethodHandle ;
2536
2637 public override bool Equals ( object ? obj ) => obj is VirtualResolutionData other && Equals ( other ) ;
2738
28- public override int GetHashCode ( ) => ( int ) ( ( uint ) MethodTable ^ ( BitOperations . RotateLeft ( ( uint ) ClassHandleTargetMethod , 5 ) ) ^ ( BitOperations . RotateRight ( ( uint ) MethodHandle , 5 ) ) ) ;
39+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
40+ public override int GetHashCode ( ) => HashCode ;
2941 }
3042
3143 private struct VirtualFunctionPointerArgs
@@ -58,15 +70,15 @@ internal static void ClearCache()
5870 private static unsafe IntPtr VirtualFunctionPointerSlowpath ( object obj , IntPtr classHandle , IntPtr methodHandle )
5971 {
6072 IntPtr result = JIT_ResolveVirtualFunctionPointer ( ObjectHandleOnStack . Create ( ref obj ) , classHandle , methodHandle ) ;
61- s_virtualFunctionPointerCache . TrySet ( new VirtualResolutionData { MethodTable = RuntimeHelpers . GetMethodTable ( obj ) , ClassHandleTargetMethod = classHandle , MethodHandle = methodHandle } , result ) ;
73+ s_virtualFunctionPointerCache . TrySet ( new VirtualResolutionData ( RuntimeHelpers . GetMethodTable ( obj ) , classHandle , methodHandle ) , result ) ;
6274 GC . KeepAlive ( obj ) ;
6375 return result ;
6476 }
6577
6678 [ DebuggerHidden ]
6779 private static unsafe IntPtr VirtualFunctionPointer ( object obj , IntPtr classHandle , IntPtr methodHandle )
6880 {
69- if ( s_virtualFunctionPointerCache . TryGet ( new VirtualResolutionData { MethodTable = RuntimeHelpers . GetMethodTable ( obj ) , ClassHandleTargetMethod = classHandle , MethodHandle = methodHandle } , out IntPtr result ) )
81+ if ( s_virtualFunctionPointerCache . TryGet ( new VirtualResolutionData ( RuntimeHelpers . GetMethodTable ( obj ) , classHandle , methodHandle ) , out IntPtr result ) )
7082 {
7183 return result ;
7284 }
@@ -79,7 +91,7 @@ private static unsafe IntPtr VirtualFunctionPointer_Dynamic(object obj, ref Virt
7991 IntPtr classHandle = virtualFunctionPointerArgs . classHnd ;
8092 IntPtr methodHandle = virtualFunctionPointerArgs . methodHnd ;
8193
82- if ( s_virtualFunctionPointerCache . TryGet ( new VirtualResolutionData { MethodTable = RuntimeHelpers . GetMethodTable ( obj ) , ClassHandleTargetMethod = classHandle , MethodHandle = methodHandle } , out IntPtr result ) )
94+ if ( s_virtualFunctionPointerCache . TryGet ( new VirtualResolutionData ( RuntimeHelpers . GetMethodTable ( obj ) , classHandle , methodHandle ) , out IntPtr result ) )
8395 {
8496 return result ;
8597 }
0 commit comments