diff --git a/Orm/Xtensive.Orm/Reflection/TypeHelper.cs b/Orm/Xtensive.Orm/Reflection/TypeHelper.cs index 011c19f2bb..1db089ce15 100644 --- a/Orm/Xtensive.Orm/Reflection/TypeHelper.cs +++ b/Orm/Xtensive.Orm/Reflection/TypeHelper.cs @@ -84,6 +84,8 @@ public int GetHashCode((Type, Type[]) obj) private static readonly Func<(Type genericDefinition, Type typeArgument1, Type typeArgument2), Type> GenericTypeFactory2 = key => key.genericDefinition.MakeGenericType(key.typeArgument1, key.typeArgument2); + private static readonly ConcurrentDictionary<(Type Type, bool UseShortForm), string> MemoizedTypeNames = new(); + private static int createDummyTypeNumber = 0; private static AssemblyBuilder assemblyBuilder; private static ModuleBuilder moduleBuilder; @@ -822,13 +824,15 @@ public static string GetShortName(this Type type) return $"{declaringType.GetShortName()}+{type.InnerGetTypeName(useShortForm: true)}"; } - private static string InnerGetTypeName(this Type type, bool useShortForm) - { - var result = useShortForm + private static string InnerGetTypeName(this Type type, bool useShortForm) => + MemoizedTypeNames.GetOrAdd((type, useShortForm), TypeNameFactory); + + private static readonly Func<(Type Type, bool UseShortForm), string> TypeNameFactory = t => { + var (type, useShortForm) = t; + + var result = useShortForm || type.DeclaringType != null // Is nested ? type.Name - : type.DeclaringType != null // Is nested - ? type.Name - : type.Namespace + "." + type.Name; + : $"{type.Namespace}.{type.Name}"; var arrayBracketPosition = result.IndexOf('['); if (arrayBracketPosition > 0) { @@ -876,7 +880,7 @@ private static string InnerGetTypeName(this Type type, bool useShortForm) result = sb.ToString(); } return result; - } + }; /// /// Indicates whether is a type.