Skip to content

Commit cbc2a82

Browse files
authored
Merge pull request #333 from DataObjects-NET/master-type-names-opt
Optimize getting of ShortName of System.Type
2 parents 797fc69 + 86c9d77 commit cbc2a82

19 files changed

+78
-64
lines changed

Orm/Xtensive.Orm/Comparison/ComparerProvider.cs

+16-10
Original file line numberDiff line numberDiff line change
@@ -66,30 +66,36 @@ protected override TAssociate CreateAssociate<TKey, TAssociate>(out Type foundFo
6666
// the comparer.
6767
var comparer = base.CreateAssociate<TKey, IAdvancedComparerBase>(out foundFor);
6868
if (foundFor == null) {
69-
CoreLog.Warning(nameof(Strings.LogCantFindAssociateFor),
70-
TypeSuffixes.ToDelimitedString(" \\ "),
71-
typeof(TAssociate).GetShortName(),
72-
typeof(TKey).GetShortName());
69+
if (CoreLog.IsLogged(Orm.Logging.LogLevel.Warning)) {
70+
CoreLog.Warning(nameof(Strings.LogCantFindAssociateFor),
71+
TypeSuffixes.ToDelimitedString(" \\ "),
72+
typeof(TAssociate).GetShortName(),
73+
typeof(TKey).GetShortName());
74+
}
7375
return null;
7476
}
7577
if (foundFor == typeof(TKey)) {
7678
return (TAssociate) comparer;
7779
}
7880
associate = BaseComparerWrapperType.Activate(new[] { typeof(TKey), foundFor }, ConstructorParams) as TAssociate;
7981
if (associate != null) {
80-
CoreLog.Warning(nameof(Strings.LogGenericAssociateIsUsedFor),
82+
if (CoreLog.IsLogged(Orm.Logging.LogLevel.Warning)) {
83+
CoreLog.Warning(nameof(Strings.LogGenericAssociateIsUsedFor),
8184
BaseComparerWrapperType.GetShortName(),
82-
typeof (TKey).GetShortName(),
85+
typeof(TKey).GetShortName(),
8386
foundFor.GetShortName(),
84-
typeof (TKey).GetShortName());
87+
typeof(TKey).GetShortName());
88+
}
8589
return associate;
8690
}
8791
else {
88-
CoreLog.Warning(nameof(Strings.LogGenericAssociateCreationHasFailedFor),
92+
if (CoreLog.IsLogged(Orm.Logging.LogLevel.Warning)) {
93+
CoreLog.Warning(nameof(Strings.LogGenericAssociateCreationHasFailedFor),
8994
BaseComparerWrapperType.GetShortName(),
90-
typeof (TKey).GetShortName(),
95+
typeof(TKey).GetShortName(),
9196
foundFor.GetShortName(),
92-
typeof (TKey).GetShortName());
97+
typeof(TKey).GetShortName());
98+
}
9399
return null;
94100
}
95101
}

Orm/Xtensive.Orm/IoC/ServiceContainer.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ namespace Xtensive.IoC
2727
[Serializable]
2828
public class ServiceContainer : ServiceContainerBase
2929
{
30-
private static readonly Type typeofIServiceContainer = typeof(IServiceContainer);
30+
private static readonly Type iServiceContainerType = typeof(IServiceContainer);
3131

3232
private static readonly Func<ServiceRegistration, Pair<ConstructorInfo, ParameterInfo[]>> ConstructorFactory = serviceInfo => {
3333
var mappedType = serviceInfo.MappedType;
@@ -187,9 +187,9 @@ public static IServiceContainer Create(Type containerType, object configuration)
187187
public static IServiceContainer Create(Type containerType, object configuration, IServiceContainer parent)
188188
{
189189
ArgumentValidator.EnsureArgumentNotNull(containerType, "containerType");
190-
if (!typeofIServiceContainer.IsAssignableFrom(containerType))
190+
if (!iServiceContainerType.IsAssignableFrom(containerType))
191191
throw new ArgumentException(string.Format(
192-
Strings.ExContainerTypeMustImplementX, typeofIServiceContainer.GetShortName()), "containerType");
192+
Strings.ExContainerTypeMustImplementX, iServiceContainerType.Name), "containerType");
193193

194194
Type configurationType = configuration?.GetType(),
195195
parentType = parent?.GetType();

Orm/Xtensive.Orm/Modelling/Actions/NodeAction.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,7 @@ public override string ToString()
105105
/// <returns>The name of the action.</returns>
106106
protected virtual string GetActionName()
107107
{
108-
string sn = GetType().GetShortName();
109-
return sn.TryCutSuffix("Action");
108+
return GetType().Name.TryCutSuffix("Action");
110109
}
111110

112111
/// <summary>

Orm/Xtensive.Orm/Modelling/Comparison/Difference.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,10 @@ public abstract class Difference : IDifference
4343
/// <inheritdoc/>
4444
public override string ToString()
4545
{
46+
var diffType = GetType();
4647
return string.Format(Strings.DifferenceFormat,
47-
GetType().GetShortName(), Source, Target, ParametersToString());
48+
diffType.IsGenericType ? diffType.GetShortName() : diffType.Name,
49+
Source, Target, ParametersToString());
4850
}
4951

5052
/// <summary>

Orm/Xtensive.Orm/Modelling/Comparison/Upgrader.cs

+13-11
Original file line numberDiff line numberDiff line change
@@ -160,18 +160,20 @@ public IReadOnlyList<NodeAction> GetUpgradeSequence(Difference difference, HintS
160160
.ForEach(validationHints.Add);
161161
var diff = comparer.Compare(CurrentModel, TargetModel, validationHints);
162162
if (diff != null) {
163-
using (CoreLog.InfoRegion(nameof(Strings.LogAutomaticUpgradeSequenceValidation))) {
164-
CoreLog.Info(nameof(Strings.LogValidationFailed));
165-
CoreLog.Info(nameof(Strings.LogItemFormat), Strings.Difference);
166-
CoreLog.Info(diff.ToString());
167-
CoreLog.Info(Strings.LogItemFormat + "\r\n{1}", Strings.UpgradeSequence,
168-
new ActionSequence() { actions });
169-
CoreLog.Info(nameof(Strings.LogItemFormat), Strings.ExpectedTargetModel);
170-
TargetModel.Dump();
171-
CoreLog.Info(nameof(Strings.LogItemFormat), Strings.ActualTargetModel);
172-
CurrentModel.Dump();
173-
throw new InvalidOperationException(Strings.ExUpgradeSequenceValidationFailure);
163+
if (CoreLog.IsLogged(Orm.Logging.LogLevel.Info)) {
164+
using (CoreLog.InfoRegion(nameof(Strings.LogAutomaticUpgradeSequenceValidation))) {
165+
CoreLog.Info(nameof(Strings.LogValidationFailed));
166+
CoreLog.Info(nameof(Strings.LogItemFormat), Strings.Difference);
167+
CoreLog.Info(diff.ToString());
168+
CoreLog.Info(Strings.LogItemFormat + "\r\n{1}", Strings.UpgradeSequence,
169+
new ActionSequence() { actions });
170+
CoreLog.Info(nameof(Strings.LogItemFormat), Strings.ExpectedTargetModel);
171+
TargetModel.Dump();
172+
CoreLog.Info(nameof(Strings.LogItemFormat), Strings.ActualTargetModel);
173+
CurrentModel.Dump();
174+
}
174175
}
176+
throw new InvalidOperationException(Strings.ExUpgradeSequenceValidationFailure);
175177
}
176178

177179
return new ReadOnlyCollection<NodeAction>(actions.Actions.ToArray());

Orm/Xtensive.Orm/Orm/Building/Builders/DomainBuilder.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public static Domain Run(DomainBuilderConfiguration builderConfiguration)
3333
ArgumentValidator.EnsureArgumentNotNull(builderConfiguration, nameof(builderConfiguration));
3434

3535
var context = new BuildingContext(builderConfiguration);
36-
using (BuildLog.InfoRegion(nameof(Strings.LogBuildingX), typeof(Domain).GetShortName())) {
36+
using (BuildLog.InfoRegion(nameof(Strings.LogBuildingX), typeof(Domain).Name)) {
3737
new DomainBuilder(context).Run();
3838
}
3939

@@ -51,7 +51,7 @@ private void Run()
5151

5252
private void CreateDomain()
5353
{
54-
using (BuildLog.InfoRegion(nameof(Strings.LogCreatingX), typeof(Domain).GetShortName())) {
54+
using (BuildLog.InfoRegion(nameof(Strings.LogCreatingX), typeof(Domain).Name)) {
5555
var services = context.BuilderConfiguration.Services;
5656
var useSingleConnection =
5757
services.ProviderInfo.Supports(ProviderFeatures.SingleConnection)
@@ -69,7 +69,7 @@ private void CreateHandlers()
6969
var handlers = context.Domain.Handlers;
7070
var services = context.BuilderConfiguration.Services;
7171

72-
using (BuildLog.InfoRegion(nameof(Strings.LogCreatingX), typeof(DomainHandler).GetShortName())) {
72+
using (BuildLog.InfoRegion(nameof(Strings.LogCreatingX), typeof(DomainHandler).Name)) {
7373
// HandlerFactory
7474
handlers.Factory = services.HandlerFactory;
7575

@@ -93,7 +93,7 @@ private void CreateHandlers()
9393

9494
private void CreateServices()
9595
{
96-
using (BuildLog.InfoRegion(nameof(Strings.LogCreatingX), typeof(IServiceContainer).GetShortName())) {
96+
using (BuildLog.InfoRegion(nameof(Strings.LogCreatingX), typeof(IServiceContainer).Name)) {
9797
var domain = context.Domain;
9898
var configuration = domain.Configuration;
9999
var userContainerType = configuration.ServiceContainerType ?? typeof(ServiceContainer);

Orm/Xtensive.Orm/Orm/Building/Builders/StorageMappingBuilder.cs

+7-5
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,18 @@ private void ProcessAll()
9292

9393
foreach (var type in typesToProcess) {
9494
var underlyingType = type.UnderlyingType;
95-
if (verbose)
95+
if (verbose && BuildLog.IsLogged(LogLevel.Info)) {
9696
BuildLog.Info(nameof(Strings.LogProcessingX), underlyingType.GetShortName());
97+
}
9798
var request = new MappingRequest(underlyingType.Assembly, underlyingType.Namespace);
98-
MappingResult result;
99-
if (!mappingCache.TryGetValue(request, out result)) {
99+
if (!mappingCache.TryGetValue(request, out var result)) {
100100
result = Process(underlyingType);
101101
mappingCache.Add(request, result);
102102
}
103103
else {
104-
if (verbose)
104+
if (verbose && BuildLog.IsLogged(LogLevel.Info)) {
105105
BuildLog.Info(nameof(Strings.LogReusingCachedMappingInformationForX), underlyingType.GetShortName());
106+
}
106107
}
107108
type.MappingDatabase = result.MappingDatabase;
108109
type.MappingSchema = result.MappingSchema;
@@ -116,8 +117,9 @@ private MappingResult Process(Type type)
116117
var resultDatabase = !string.IsNullOrEmpty(rule.Database) ? rule.Database : defaultDatabase;
117118
var resultSchema = !string.IsNullOrEmpty(rule.Schema) ? rule.Schema : defaultSchema;
118119

119-
if (verbose)
120+
if (verbose && BuildLog.IsLogged(LogLevel.Info)) {
120121
BuildLog.Info(nameof(Strings.ApplyingRuleXToY), rule, type.GetShortName());
122+
}
121123

122124
return new MappingResult(resultDatabase, resultSchema);
123125
}

Orm/Xtensive.Orm/Orm/Key.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -305,15 +305,16 @@ public static Key Parse([NotNull] Domain domain, string source)
305305
/// <inheritdoc/>
306306
public override string ToString()
307307
{
308+
var underlyingType = TypeInfo?.UnderlyingType ?? TypeReference.Type.UnderlyingType;
308309
if (TypeInfo!=null)
309310
return string.Format(
310311
Strings.KeyFormat,
311-
TypeInfo.UnderlyingType.GetShortName(),
312+
underlyingType.IsGenericType || underlyingType.IsNested ? underlyingType.GetShortName() : underlyingType.Name,
312313
Value.ToRegular());
313314

314315
return string.Format(
315316
Strings.KeyFormatUnknownKeyType,
316-
TypeReference.Type.UnderlyingType.GetShortName(),
317+
underlyingType.IsGenericType || underlyingType.IsNested ? underlyingType.GetShortName() : underlyingType.Name,
317318
Value.ToRegular());
318319
}
319320

Orm/Xtensive.Orm/Orm/Linq/TranslatorContext.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ public ApplyParameter GetApplyParameter(CompilableProvider provider)
8080
{
8181
ApplyParameter parameter;
8282
if (!applyParameters.TryGetValue(provider, out parameter)) {
83-
parameter = new ApplyParameter(provider.GetType().GetShortName());
83+
var providerType = provider.GetType();
84+
parameter = new ApplyParameter(providerType.IsGenericType ? providerType.GetShortName() : providerType.Name);
8485
// parameter = new ApplyParameter(provider.ToString());
8586
// ENABLE ONLY FOR DEBUGGING!
8687
// May lead TO entity.ToString() calls, while ToString can be overriden.

Orm/Xtensive.Orm/Orm/Model/Node.cs

+5-2
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,11 @@ public virtual void UpdateState()
9292
/// <inheritdoc/>
9393
public override string ToString()
9494
{
95-
return string.Format(Strings.NodeFormat,
96-
name ?? Strings.UnnamedNodeDisplayName, GetType().GetShortName());
95+
var type = GetType();
96+
97+
return string.Format(Strings.NodeFormat,
98+
name ?? Strings.UnnamedNodeDisplayName,
99+
type.IsGenericType ? type.GetShortName() : type.Name);
97100
}
98101

99102

Orm/Xtensive.Orm/Orm/Rse/Providers/Provider.cs

+9-3
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,12 @@ private set {
6060
protected abstract RecordSetHeader BuildHeader();
6161

6262
private string DebuggerDisplayName {
63-
get { return GetType().GetShortName(); }
63+
get {
64+
var type = GetType();
65+
return type.IsGenericType
66+
? type.GetShortName()
67+
: type.Name;
68+
}
6469
}
6570

6671
/// <summary>
@@ -98,8 +103,9 @@ private void AppendTitleTo(StringBuilder sb, int indent)
98103
private string TitleToString()
99104
{
100105
var sb = new StringBuilder();
101-
string providerName = GetType().GetShortName().TryCutSuffix(ToString_ProviderTypeSuffix);
102-
string parameters = ParametersToString();
106+
var type = GetType();
107+
var providerName = (type.IsGenericType ? type.GetShortName() : type.Name).TryCutSuffix(ToString_ProviderTypeSuffix);
108+
var parameters = ParametersToString();
103109

104110
sb.Append(providerName);
105111
if (!parameters.IsNullOrEmpty())

Orm/Xtensive.Orm/Orm/Upgrade/UpgradingDomainBuilder.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ where handler.IsEnabled
362362
var candidates = group.ToList();
363363
if (candidates.Count > 1) {
364364
throw new DomainBuilderException(
365-
string.Format(Strings.ExMoreThanOneEnabledXIsProvidedForAssemblyY, typeof (IUpgradeHandler).GetShortName(), @group.Key));
365+
string.Format(Strings.ExMoreThanOneEnabledXIsProvidedForAssemblyY, typeof(IUpgradeHandler).Name, @group.Key));
366366
}
367367
handlers.Add(group.Key, candidates[0]);
368368
}
@@ -398,12 +398,12 @@ private static void BuildFullTextCatalogResolver(UpgradeServiceAccessor serviceA
398398
//Getting user resolvers
399399
var candidates = from r in serviceContainer.GetAll<IFullTextCatalogNameBuilder>()
400400
let assembly = r.GetType().Assembly
401-
where r.IsEnabled && assembly!=typeof (IFullTextCatalogNameBuilder).Assembly
401+
where r.IsEnabled && assembly!=typeof(IFullTextCatalogNameBuilder).Assembly
402402
select r;
403403

404404
var userResolversCount = candidates.Count();
405405
if (userResolversCount > 1)
406-
throw new DomainBuilderException(string.Format(Strings.ExMoreThanOneEnabledXIsProvided, typeof (IFullTextCatalogNameBuilder).GetShortName()));
406+
throw new DomainBuilderException(string.Format(Strings.ExMoreThanOneEnabledXIsProvided, typeof(IFullTextCatalogNameBuilder).Name));
407407

408408
var resolver = (userResolversCount==0)
409409
? new FullTextCatalogNameBuilder()

Orm/Xtensive.Orm/Reflection/DelegateHelper.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ public static TDelegate CreateDelegate<TDelegate>(object callTarget, Type type,
357357
Type delegateType = typeof (TDelegate);
358358
if (!WellKnownTypes.Delegate.IsAssignableFrom(delegateType))
359359
throw new ArgumentException(string.Format(Strings.ExGenericParameterShouldBeOfTypeT,
360-
"TDelegate", WellKnownTypes.Delegate.GetShortName()));
360+
"TDelegate", WellKnownTypes.Delegate.Name));
361361

362362
BindingFlags bindingFlags =
363363
BindingFlags.Public |
@@ -404,7 +404,7 @@ public static TDelegate[] CreateDelegates<TDelegate>(object callTarget, Type typ
404404
Type delegateType = typeof (TDelegate);
405405
if (!WellKnownTypes.Delegate.IsAssignableFrom(delegateType))
406406
throw new ArgumentException(string.Format(Strings.ExGenericParameterShouldBeOfTypeT,
407-
"TDelegate", WellKnownTypes.Delegate.GetShortName()));
407+
"TDelegate", WellKnownTypes.Delegate.Name));
408408

409409
int count = genericArgumentVariants.Count;
410410
TDelegate[] delegates = new TDelegate[count];

Orm/Xtensive.Orm/Tuples/Transform/CombineTransform.cs

+1-3
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@ public IReadOnlyList<TupleDescriptor> Sources
4747
public override string ToString()
4848
{
4949
string description = $"{sources.ToDelimitedString(" + ")}, {(IsReadOnly ? Strings.ReadOnlyShort : Strings.ReadWriteShort)}";
50-
return string.Format(Strings.TupleTransformFormat,
51-
GetType().GetShortName(),
52-
description);
50+
return string.Format(Strings.TupleTransformFormat, GetType().Name, description);
5351
}
5452

5553

Orm/Xtensive.Orm/Tuples/Transform/CutInTransform.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ public IReadOnlyList<TupleDescriptor> Sources
4949
public override string ToString()
5050
{
5151
string description = $"{sources.ToDelimitedString(" + ")}, {(IsReadOnly ? Strings.ReadOnlyShort : Strings.ReadWriteShort)}";
52-
return string.Format(Strings.TupleTransformFormat,
53-
GetType().GetShortName(),
52+
return string.Format(Strings.TupleTransformFormat, GetType().Name,
5453
description);
5554
}
5655

Orm/Xtensive.Orm/Tuples/Transform/CutOutTransform.cs

+1-3
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ public Segment<int> Segment
4040
public override string ToString()
4141
{
4242
string description = $"{segment}, {(IsReadOnly ? Strings.ReadOnlyShort : Strings.ReadWriteShort)}";
43-
return string.Format(Strings.TupleTransformFormat,
44-
GetType().GetShortName(),
45-
description);
43+
return string.Format(Strings.TupleTransformFormat, GetType().Name, description);
4644
}
4745

4846

Orm/Xtensive.Orm/Tuples/Transform/MapTransform.cs

+1-3
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,7 @@ protected Tuple Apply(TupleTransformType transformType, Tuple source1, Tuple sou
256256
public override string ToString()
257257
{
258258
string description = $"{SourceCount}: {(SourceCount == 1 ? singleSourceMap.ToCommaDelimitedString() : map.ToCommaDelimitedString())}, {(isReadOnly ? Strings.ReadOnlyShort : Strings.ReadWriteShort)}";
259-
return string.Format(Strings.TupleTransformFormat,
260-
GetType().GetShortName(),
261-
description);
259+
return string.Format(Strings.TupleTransformFormat, GetType().Name, description);
262260
}
263261

264262

Orm/Xtensive.Orm/Tuples/Transform/SegmentTransform.cs

+1-3
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ public Segment<int> Segment
3939
public override string ToString()
4040
{
4141
string description = $"{segment}, {(IsReadOnly ? Strings.ReadOnlyShort : Strings.ReadWriteShort)}";
42-
return string.Format(Strings.TupleTransformFormat,
43-
GetType().GetShortName(),
44-
description);
42+
return string.Format(Strings.TupleTransformFormat, GetType().Name, description);
4543
}
4644

4745

Orm/Xtensive.Orm/Tuples/Transform/TupleTransformBase.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ public virtual bool IsReadOnly {
5050
/// <inheritdoc/>
5151
public override string ToString()
5252
{
53-
return GetType().GetShortName();
53+
var type = GetType();
54+
return type.IsGenericType ? type.GetShortName() : type.Name;
5455
}
5556
}
5657
}

0 commit comments

Comments
 (0)