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

Lines changed: 78 additions & 64 deletions

File tree

Orm/Xtensive.Orm/Comparison/ComparerProvider.cs

Lines changed: 16 additions & 10 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 1 addition & 2 deletions
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

Lines changed: 3 additions & 1 deletion
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

Lines changed: 13 additions & 11 deletions
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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 7 additions & 5 deletions
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

Lines changed: 3 additions & 2 deletions
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 5 additions & 2 deletions
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

0 commit comments

Comments
 (0)