Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Prev Previous commit
Next Next commit
Factor out the slow path into a non-inlineable method
  • Loading branch information
jkotas committed Nov 20, 2022
commit b7c990b6305b027d59bab2b65b8dd0e957c31c17
21 changes: 10 additions & 11 deletions src/coreclr/System.Private.CoreLib/src/System/RuntimeHandles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -689,20 +689,19 @@ internal RuntimeType MakePointer()

internal static RuntimeType GetGenericTypeDefinition(RuntimeType type)
{
if (HasInstantiation(type) && !IsGenericTypeDefinition(type))
{
if (type.GenericCache is not RuntimeType genericDefinition)
{
RuntimeTypeHandle nativeHandle = type.TypeHandle;
genericDefinition = null!;
GetGenericTypeDefinition(new QCallTypeHandle(ref nativeHandle), ObjectHandleOnStack.Create(ref genericDefinition));
type.GenericCache = genericDefinition;
}
Debug.Assert(HasInstantiation(type));

return IsGenericTypeDefinition(type) ? type :
type.GenericCache is RuntimeType genericDefinition ? genericDefinition : CacheGenericDefinition(type);

[MethodImpl(MethodImplOptions.NoInlining)]
static RuntimeType CacheGenericDefinition(RuntimeType type)
{
RuntimeType genericDefinition = null!;
GetGenericTypeDefinition(new QCallTypeHandle(ref type), ObjectHandleOnStack.Create(ref genericDefinition));
type.GenericCache = genericDefinition;
return genericDefinition;
}

return type;
}

[MethodImpl(MethodImplOptions.InternalCall)]
Expand Down