diff options
author | Michal Strehovsky <michals@microsoft.com> | 2017-11-23 18:34:16 +0300 |
---|---|---|
committer | Michal Strehovsky <michals@microsoft.com> | 2017-11-23 18:34:16 +0300 |
commit | 835423c91aa2bb2d3e7862bc8a579f61a665e0ea (patch) | |
tree | 232b1ef9f205ff94028f80fad2646677b9c0e571 /src/System.Private.Reflection.Core | |
parent | ffc68d150967e6b05f561f81872ec3ddc9925fd8 (diff) |
Avoid rooting type loader in TypeUnifier unless necessary
Having a single code path that is used for dissecting and building new types saves a couple lines, but it's hostile to treeshaking.
[tfs-changeset: 1681992]
Diffstat (limited to 'src/System.Private.Reflection.Core')
-rw-r--r-- | src/System.Private.Reflection.Core/src/System/Reflection/Runtime/General/TypeUnifier.cs | 53 |
1 files changed, 29 insertions, 24 deletions
diff --git a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/General/TypeUnifier.cs b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/General/TypeUnifier.cs index 10082a650..98d338020 100644 --- a/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/General/TypeUnifier.cs +++ b/src/System.Private.Reflection.Core/src/System/Reflection/Runtime/General/TypeUnifier.cs @@ -37,37 +37,31 @@ namespace System.Reflection.Runtime.General { internal static partial class TypeUnifier { - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static RuntimeTypeInfo GetArrayType(this RuntimeTypeInfo elementType) { - return elementType.GetArrayType(default(RuntimeTypeHandle)); + return RuntimeArrayTypeInfo.GetArrayTypeInfo(elementType, multiDim: false, rank: 1); } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static RuntimeTypeInfo GetMultiDimArrayType(this RuntimeTypeInfo elementType, int rank) { - return elementType.GetMultiDimArrayType(rank, default(RuntimeTypeHandle)); + return RuntimeArrayTypeInfo.GetArrayTypeInfo(elementType, multiDim: true, rank: rank); } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static RuntimeTypeInfo GetByRefType(this RuntimeTypeInfo targetType) { - return targetType.GetByRefType(default(RuntimeTypeHandle)); + return RuntimeByRefTypeInfo.GetByRefTypeInfo(targetType); } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static RuntimeTypeInfo GetPointerType(this RuntimeTypeInfo targetType) { - return targetType.GetPointerType(default(RuntimeTypeHandle)); + return RuntimePointerTypeInfo.GetPointerTypeInfo(targetType); } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static RuntimeTypeInfo GetConstructedGenericType(this RuntimeTypeInfo genericTypeDefinition, RuntimeTypeInfo[] genericTypeArguments) { - return genericTypeDefinition.GetConstructedGenericType(genericTypeArguments, default(RuntimeTypeHandle)); + return RuntimeConstructedGenericTypeInfo.GetRuntimeConstructedGenericTypeInfo(genericTypeDefinition, genericTypeArguments); } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static RuntimeTypeInfo GetTypeForRuntimeTypeHandle(this RuntimeTypeHandle typeHandle) { Type type = Type.GetTypeFromHandle(typeHandle); @@ -80,31 +74,26 @@ namespace System.Reflection.Runtime.General // waste cycles looking up the handle again from the mapping tables.) //====================================================================================================== - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static RuntimeTypeInfo GetArrayType(this RuntimeTypeInfo elementType, RuntimeTypeHandle precomputedTypeHandle) { return RuntimeArrayTypeInfo.GetArrayTypeInfo(elementType, multiDim: false, rank: 1, precomputedTypeHandle: precomputedTypeHandle); } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static RuntimeTypeInfo GetMultiDimArrayType(this RuntimeTypeInfo elementType, int rank, RuntimeTypeHandle precomputedTypeHandle) { return RuntimeArrayTypeInfo.GetArrayTypeInfo(elementType, multiDim: true, rank: rank, precomputedTypeHandle: precomputedTypeHandle); } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static RuntimeTypeInfo GetPointerType(this RuntimeTypeInfo targetType, RuntimeTypeHandle precomputedTypeHandle) { return RuntimePointerTypeInfo.GetPointerTypeInfo(targetType, precomputedTypeHandle); } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static RuntimeTypeInfo GetByRefType(this RuntimeTypeInfo targetType, RuntimeTypeHandle precomputedTypeHandle) { return RuntimeByRefTypeInfo.GetByRefTypeInfo(targetType, precomputedTypeHandle); } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static RuntimeTypeInfo GetConstructedGenericType(this RuntimeTypeInfo genericTypeDefinition, RuntimeTypeInfo[] genericTypeArguments, RuntimeTypeHandle precomputedTypeHandle) { return RuntimeConstructedGenericTypeInfo.GetRuntimeConstructedGenericTypeInfo(genericTypeDefinition, genericTypeArguments, precomputedTypeHandle); @@ -194,12 +183,16 @@ namespace System.Reflection.Runtime.TypeInfos //----------------------------------------------------------------------------------------------------------- internal sealed partial class RuntimeArrayTypeInfo : RuntimeHasElementTypeInfo { + internal static RuntimeArrayTypeInfo GetArrayTypeInfo(RuntimeTypeInfo elementType, bool multiDim, int rank) + { + return GetArrayTypeInfo(elementType, multiDim, rank, GetRuntimeTypeHandleIfAny(elementType, multiDim, rank)); + } + internal static RuntimeArrayTypeInfo GetArrayTypeInfo(RuntimeTypeInfo elementType, bool multiDim, int rank, RuntimeTypeHandle precomputedTypeHandle) { Debug.Assert(multiDim || rank == 1); - RuntimeTypeHandle typeHandle = precomputedTypeHandle.IsNull() ? GetRuntimeTypeHandleIfAny(elementType, multiDim, rank) : precomputedTypeHandle; - UnificationKey key = new UnificationKey(elementType, typeHandle); + UnificationKey key = new UnificationKey(elementType, precomputedTypeHandle); RuntimeArrayTypeInfo type; if (!multiDim) type = ArrayTypeTable.Table.GetOrAdd(key); @@ -294,10 +287,14 @@ namespace System.Reflection.Runtime.TypeInfos //----------------------------------------------------------------------------------------------------------- internal sealed partial class RuntimeByRefTypeInfo : RuntimeHasElementTypeInfo { + internal static RuntimeByRefTypeInfo GetByRefTypeInfo(RuntimeTypeInfo elementType) + { + return GetByRefTypeInfo(elementType, GetRuntimeTypeHandleIfAny(elementType)); + } + internal static RuntimeByRefTypeInfo GetByRefTypeInfo(RuntimeTypeInfo elementType, RuntimeTypeHandle precomputedTypeHandle) { - RuntimeTypeHandle typeHandle = precomputedTypeHandle.IsNull() ? GetRuntimeTypeHandleIfAny(elementType) : precomputedTypeHandle; - RuntimeByRefTypeInfo type = ByRefTypeTable.Table.GetOrAdd(new UnificationKey(elementType, typeHandle)); + RuntimeByRefTypeInfo type = ByRefTypeTable.Table.GetOrAdd(new UnificationKey(elementType, precomputedTypeHandle)); type.EstablishDebugName(); return type; } @@ -334,10 +331,14 @@ namespace System.Reflection.Runtime.TypeInfos //----------------------------------------------------------------------------------------------------------- internal sealed partial class RuntimePointerTypeInfo : RuntimeHasElementTypeInfo { + internal static RuntimePointerTypeInfo GetPointerTypeInfo(RuntimeTypeInfo elementType) + { + return GetPointerTypeInfo(elementType, precomputedTypeHandle: GetRuntimeTypeHandleIfAny(elementType)); + } + internal static RuntimePointerTypeInfo GetPointerTypeInfo(RuntimeTypeInfo elementType, RuntimeTypeHandle precomputedTypeHandle) { - RuntimeTypeHandle typeHandle = precomputedTypeHandle.IsNull() ? GetRuntimeTypeHandleIfAny(elementType) : precomputedTypeHandle; - RuntimePointerTypeInfo type = PointerTypeTable.Table.GetOrAdd(new UnificationKey(elementType, typeHandle)); + RuntimePointerTypeInfo type = PointerTypeTable.Table.GetOrAdd(new UnificationKey(elementType, precomputedTypeHandle)); type.EstablishDebugName(); return type; } @@ -374,10 +375,14 @@ namespace System.Reflection.Runtime.TypeInfos //----------------------------------------------------------------------------------------------------------- internal sealed partial class RuntimeConstructedGenericTypeInfo : RuntimeTypeInfo, IKeyedItem<RuntimeConstructedGenericTypeInfo.UnificationKey> { + internal static RuntimeConstructedGenericTypeInfo GetRuntimeConstructedGenericTypeInfo(RuntimeTypeInfo genericTypeDefinition, RuntimeTypeInfo[] genericTypeArguments) + { + return GetRuntimeConstructedGenericTypeInfo(genericTypeDefinition, genericTypeArguments, precomputedTypeHandle: GetRuntimeTypeHandleIfAny(genericTypeDefinition, genericTypeArguments)); + } + internal static RuntimeConstructedGenericTypeInfo GetRuntimeConstructedGenericTypeInfo(RuntimeTypeInfo genericTypeDefinition, RuntimeTypeInfo[] genericTypeArguments, RuntimeTypeHandle precomputedTypeHandle) { - RuntimeTypeHandle typeHandle = precomputedTypeHandle.IsNull() ? GetRuntimeTypeHandleIfAny(genericTypeDefinition, genericTypeArguments) : precomputedTypeHandle; - UnificationKey key = new UnificationKey(genericTypeDefinition, genericTypeArguments, typeHandle); + UnificationKey key = new UnificationKey(genericTypeDefinition, genericTypeArguments, precomputedTypeHandle); RuntimeConstructedGenericTypeInfo typeInfo = ConstructedGenericTypeTable.Table.GetOrAdd(key); typeInfo.EstablishDebugName(); return typeInfo; |