Skip to content

Optimize getting of ShortName of System.Type #333

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions Orm/Xtensive.Orm/Comparison/ComparerProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,30 +66,36 @@ protected override TAssociate CreateAssociate<TKey, TAssociate>(out Type foundFo
// the comparer.
var comparer = base.CreateAssociate<TKey, IAdvancedComparerBase>(out foundFor);
if (foundFor == null) {
CoreLog.Warning(nameof(Strings.LogCantFindAssociateFor),
TypeSuffixes.ToDelimitedString(" \\ "),
typeof(TAssociate).GetShortName(),
typeof(TKey).GetShortName());
if (CoreLog.IsLogged(Orm.Logging.LogLevel.Warning)) {
CoreLog.Warning(nameof(Strings.LogCantFindAssociateFor),
TypeSuffixes.ToDelimitedString(" \\ "),
typeof(TAssociate).GetShortName(),
typeof(TKey).GetShortName());
}
return null;
}
if (foundFor == typeof(TKey)) {
return (TAssociate) comparer;
}
associate = BaseComparerWrapperType.Activate(new[] { typeof(TKey), foundFor }, ConstructorParams) as TAssociate;
if (associate != null) {
CoreLog.Warning(nameof(Strings.LogGenericAssociateIsUsedFor),
if (CoreLog.IsLogged(Orm.Logging.LogLevel.Warning)) {
CoreLog.Warning(nameof(Strings.LogGenericAssociateIsUsedFor),
BaseComparerWrapperType.GetShortName(),
typeof (TKey).GetShortName(),
typeof(TKey).GetShortName(),
foundFor.GetShortName(),
typeof (TKey).GetShortName());
typeof(TKey).GetShortName());
}
return associate;
}
else {
CoreLog.Warning(nameof(Strings.LogGenericAssociateCreationHasFailedFor),
if (CoreLog.IsLogged(Orm.Logging.LogLevel.Warning)) {
CoreLog.Warning(nameof(Strings.LogGenericAssociateCreationHasFailedFor),
BaseComparerWrapperType.GetShortName(),
typeof (TKey).GetShortName(),
typeof(TKey).GetShortName(),
foundFor.GetShortName(),
typeof (TKey).GetShortName());
typeof(TKey).GetShortName());
}
return null;
}
}
Expand Down
6 changes: 3 additions & 3 deletions Orm/Xtensive.Orm/IoC/ServiceContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace Xtensive.IoC
[Serializable]
public class ServiceContainer : ServiceContainerBase
{
private static readonly Type typeofIServiceContainer = typeof(IServiceContainer);
private static readonly Type iServiceContainerType = typeof(IServiceContainer);

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

Type configurationType = configuration?.GetType(),
parentType = parent?.GetType();
Expand Down
3 changes: 1 addition & 2 deletions Orm/Xtensive.Orm/Modelling/Actions/NodeAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ public override string ToString()
/// <returns>The name of the action.</returns>
protected virtual string GetActionName()
{
string sn = GetType().GetShortName();
return sn.TryCutSuffix("Action");
return GetType().Name.TryCutSuffix("Action");
}

/// <summary>
Expand Down
4 changes: 3 additions & 1 deletion Orm/Xtensive.Orm/Modelling/Comparison/Difference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ public abstract class Difference : IDifference
/// <inheritdoc/>
public override string ToString()
{
var diffType = GetType();
return string.Format(Strings.DifferenceFormat,
GetType().GetShortName(), Source, Target, ParametersToString());
diffType.IsGenericType ? diffType.GetShortName() : diffType.Name,
Source, Target, ParametersToString());
}

/// <summary>
Expand Down
24 changes: 13 additions & 11 deletions Orm/Xtensive.Orm/Modelling/Comparison/Upgrader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,18 +160,20 @@ public IReadOnlyList<NodeAction> GetUpgradeSequence(Difference difference, HintS
.ForEach(validationHints.Add);
var diff = comparer.Compare(CurrentModel, TargetModel, validationHints);
if (diff != null) {
using (CoreLog.InfoRegion(nameof(Strings.LogAutomaticUpgradeSequenceValidation))) {
CoreLog.Info(nameof(Strings.LogValidationFailed));
CoreLog.Info(nameof(Strings.LogItemFormat), Strings.Difference);
CoreLog.Info(diff.ToString());
CoreLog.Info(Strings.LogItemFormat + "\r\n{1}", Strings.UpgradeSequence,
new ActionSequence() { actions });
CoreLog.Info(nameof(Strings.LogItemFormat), Strings.ExpectedTargetModel);
TargetModel.Dump();
CoreLog.Info(nameof(Strings.LogItemFormat), Strings.ActualTargetModel);
CurrentModel.Dump();
throw new InvalidOperationException(Strings.ExUpgradeSequenceValidationFailure);
if (CoreLog.IsLogged(Orm.Logging.LogLevel.Info)) {
using (CoreLog.InfoRegion(nameof(Strings.LogAutomaticUpgradeSequenceValidation))) {
CoreLog.Info(nameof(Strings.LogValidationFailed));
CoreLog.Info(nameof(Strings.LogItemFormat), Strings.Difference);
CoreLog.Info(diff.ToString());
CoreLog.Info(Strings.LogItemFormat + "\r\n{1}", Strings.UpgradeSequence,
new ActionSequence() { actions });
CoreLog.Info(nameof(Strings.LogItemFormat), Strings.ExpectedTargetModel);
TargetModel.Dump();
CoreLog.Info(nameof(Strings.LogItemFormat), Strings.ActualTargetModel);
CurrentModel.Dump();
}
}
throw new InvalidOperationException(Strings.ExUpgradeSequenceValidationFailure);
}

return new ReadOnlyCollection<NodeAction>(actions.Actions.ToArray());
Expand Down
8 changes: 4 additions & 4 deletions Orm/Xtensive.Orm/Orm/Building/Builders/DomainBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static Domain Run(DomainBuilderConfiguration builderConfiguration)
ArgumentValidator.EnsureArgumentNotNull(builderConfiguration, nameof(builderConfiguration));

var context = new BuildingContext(builderConfiguration);
using (BuildLog.InfoRegion(nameof(Strings.LogBuildingX), typeof(Domain).GetShortName())) {
using (BuildLog.InfoRegion(nameof(Strings.LogBuildingX), typeof(Domain).Name)) {
new DomainBuilder(context).Run();
}

Expand All @@ -51,7 +51,7 @@ private void Run()

private void CreateDomain()
{
using (BuildLog.InfoRegion(nameof(Strings.LogCreatingX), typeof(Domain).GetShortName())) {
using (BuildLog.InfoRegion(nameof(Strings.LogCreatingX), typeof(Domain).Name)) {
var services = context.BuilderConfiguration.Services;
var useSingleConnection =
services.ProviderInfo.Supports(ProviderFeatures.SingleConnection)
Expand All @@ -69,7 +69,7 @@ private void CreateHandlers()
var handlers = context.Domain.Handlers;
var services = context.BuilderConfiguration.Services;

using (BuildLog.InfoRegion(nameof(Strings.LogCreatingX), typeof(DomainHandler).GetShortName())) {
using (BuildLog.InfoRegion(nameof(Strings.LogCreatingX), typeof(DomainHandler).Name)) {
// HandlerFactory
handlers.Factory = services.HandlerFactory;

Expand All @@ -93,7 +93,7 @@ private void CreateHandlers()

private void CreateServices()
{
using (BuildLog.InfoRegion(nameof(Strings.LogCreatingX), typeof(IServiceContainer).GetShortName())) {
using (BuildLog.InfoRegion(nameof(Strings.LogCreatingX), typeof(IServiceContainer).Name)) {
var domain = context.Domain;
var configuration = domain.Configuration;
var userContainerType = configuration.ServiceContainerType ?? typeof(ServiceContainer);
Expand Down
12 changes: 7 additions & 5 deletions Orm/Xtensive.Orm/Orm/Building/Builders/StorageMappingBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,18 @@ private void ProcessAll()

foreach (var type in typesToProcess) {
var underlyingType = type.UnderlyingType;
if (verbose)
if (verbose && BuildLog.IsLogged(LogLevel.Info)) {
BuildLog.Info(nameof(Strings.LogProcessingX), underlyingType.GetShortName());
}
var request = new MappingRequest(underlyingType.Assembly, underlyingType.Namespace);
MappingResult result;
if (!mappingCache.TryGetValue(request, out result)) {
if (!mappingCache.TryGetValue(request, out var result)) {
result = Process(underlyingType);
mappingCache.Add(request, result);
}
else {
if (verbose)
if (verbose && BuildLog.IsLogged(LogLevel.Info)) {
BuildLog.Info(nameof(Strings.LogReusingCachedMappingInformationForX), underlyingType.GetShortName());
}
}
type.MappingDatabase = result.MappingDatabase;
type.MappingSchema = result.MappingSchema;
Expand All @@ -116,8 +117,9 @@ private MappingResult Process(Type type)
var resultDatabase = !string.IsNullOrEmpty(rule.Database) ? rule.Database : defaultDatabase;
var resultSchema = !string.IsNullOrEmpty(rule.Schema) ? rule.Schema : defaultSchema;

if (verbose)
if (verbose && BuildLog.IsLogged(LogLevel.Info)) {
BuildLog.Info(nameof(Strings.ApplyingRuleXToY), rule, type.GetShortName());
}

return new MappingResult(resultDatabase, resultSchema);
}
Expand Down
5 changes: 3 additions & 2 deletions Orm/Xtensive.Orm/Orm/Key.cs
Original file line number Diff line number Diff line change
Expand Up @@ -305,15 +305,16 @@ public static Key Parse([NotNull] Domain domain, string source)
/// <inheritdoc/>
public override string ToString()
{
var underlyingType = TypeInfo?.UnderlyingType ?? TypeReference.Type.UnderlyingType;
if (TypeInfo!=null)
return string.Format(
Strings.KeyFormat,
TypeInfo.UnderlyingType.GetShortName(),
underlyingType.IsGenericType || underlyingType.IsNested ? underlyingType.GetShortName() : underlyingType.Name,
Value.ToRegular());

return string.Format(
Strings.KeyFormatUnknownKeyType,
TypeReference.Type.UnderlyingType.GetShortName(),
underlyingType.IsGenericType || underlyingType.IsNested ? underlyingType.GetShortName() : underlyingType.Name,
Value.ToRegular());
}

Expand Down
3 changes: 2 additions & 1 deletion Orm/Xtensive.Orm/Orm/Linq/TranslatorContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ public ApplyParameter GetApplyParameter(CompilableProvider provider)
{
ApplyParameter parameter;
if (!applyParameters.TryGetValue(provider, out parameter)) {
parameter = new ApplyParameter(provider.GetType().GetShortName());
var providerType = provider.GetType();
parameter = new ApplyParameter(providerType.IsGenericType ? providerType.GetShortName() : providerType.Name);
// parameter = new ApplyParameter(provider.ToString());
// ENABLE ONLY FOR DEBUGGING!
// May lead TO entity.ToString() calls, while ToString can be overriden.
Expand Down
7 changes: 5 additions & 2 deletions Orm/Xtensive.Orm/Orm/Model/Node.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,11 @@ public virtual void UpdateState()
/// <inheritdoc/>
public override string ToString()
{
return string.Format(Strings.NodeFormat,
name ?? Strings.UnnamedNodeDisplayName, GetType().GetShortName());
var type = GetType();

return string.Format(Strings.NodeFormat,
name ?? Strings.UnnamedNodeDisplayName,
type.IsGenericType ? type.GetShortName() : type.Name);
}


Expand Down
12 changes: 9 additions & 3 deletions Orm/Xtensive.Orm/Orm/Rse/Providers/Provider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@ private set {
protected abstract RecordSetHeader BuildHeader();

private string DebuggerDisplayName {
get { return GetType().GetShortName(); }
get {
var type = GetType();
return type.IsGenericType
? type.GetShortName()
: type.Name;
}
}

/// <summary>
Expand Down Expand Up @@ -98,8 +103,9 @@ private void AppendTitleTo(StringBuilder sb, int indent)
private string TitleToString()
{
var sb = new StringBuilder();
string providerName = GetType().GetShortName().TryCutSuffix(ToString_ProviderTypeSuffix);
string parameters = ParametersToString();
var type = GetType();
var providerName = (type.IsGenericType ? type.GetShortName() : type.Name).TryCutSuffix(ToString_ProviderTypeSuffix);
var parameters = ParametersToString();

sb.Append(providerName);
if (!parameters.IsNullOrEmpty())
Expand Down
6 changes: 3 additions & 3 deletions Orm/Xtensive.Orm/Orm/Upgrade/UpgradingDomainBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ where handler.IsEnabled
var candidates = group.ToList();
if (candidates.Count > 1) {
throw new DomainBuilderException(
string.Format(Strings.ExMoreThanOneEnabledXIsProvidedForAssemblyY, typeof (IUpgradeHandler).GetShortName(), @group.Key));
string.Format(Strings.ExMoreThanOneEnabledXIsProvidedForAssemblyY, typeof(IUpgradeHandler).Name, @group.Key));
}
handlers.Add(group.Key, candidates[0]);
}
Expand Down Expand Up @@ -398,12 +398,12 @@ private static void BuildFullTextCatalogResolver(UpgradeServiceAccessor serviceA
//Getting user resolvers
var candidates = from r in serviceContainer.GetAll<IFullTextCatalogNameBuilder>()
let assembly = r.GetType().Assembly
where r.IsEnabled && assembly!=typeof (IFullTextCatalogNameBuilder).Assembly
where r.IsEnabled && assembly!=typeof(IFullTextCatalogNameBuilder).Assembly
select r;

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

var resolver = (userResolversCount==0)
? new FullTextCatalogNameBuilder()
Expand Down
4 changes: 2 additions & 2 deletions Orm/Xtensive.Orm/Reflection/DelegateHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ public static TDelegate CreateDelegate<TDelegate>(object callTarget, Type type,
Type delegateType = typeof (TDelegate);
if (!WellKnownTypes.Delegate.IsAssignableFrom(delegateType))
throw new ArgumentException(string.Format(Strings.ExGenericParameterShouldBeOfTypeT,
"TDelegate", WellKnownTypes.Delegate.GetShortName()));
"TDelegate", WellKnownTypes.Delegate.Name));

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

int count = genericArgumentVariants.Count;
TDelegate[] delegates = new TDelegate[count];
Expand Down
4 changes: 1 addition & 3 deletions Orm/Xtensive.Orm/Tuples/Transform/CombineTransform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ public IReadOnlyList<TupleDescriptor> Sources
public override string ToString()
{
string description = $"{sources.ToDelimitedString(" + ")}, {(IsReadOnly ? Strings.ReadOnlyShort : Strings.ReadWriteShort)}";
return string.Format(Strings.TupleTransformFormat,
GetType().GetShortName(),
description);
return string.Format(Strings.TupleTransformFormat, GetType().Name, description);
}


Expand Down
3 changes: 1 addition & 2 deletions Orm/Xtensive.Orm/Tuples/Transform/CutInTransform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ public IReadOnlyList<TupleDescriptor> Sources
public override string ToString()
{
string description = $"{sources.ToDelimitedString(" + ")}, {(IsReadOnly ? Strings.ReadOnlyShort : Strings.ReadWriteShort)}";
return string.Format(Strings.TupleTransformFormat,
GetType().GetShortName(),
return string.Format(Strings.TupleTransformFormat, GetType().Name,
description);
}

Expand Down
4 changes: 1 addition & 3 deletions Orm/Xtensive.Orm/Tuples/Transform/CutOutTransform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ public Segment<int> Segment
public override string ToString()
{
string description = $"{segment}, {(IsReadOnly ? Strings.ReadOnlyShort : Strings.ReadWriteShort)}";
return string.Format(Strings.TupleTransformFormat,
GetType().GetShortName(),
description);
return string.Format(Strings.TupleTransformFormat, GetType().Name, description);
}


Expand Down
4 changes: 1 addition & 3 deletions Orm/Xtensive.Orm/Tuples/Transform/MapTransform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,7 @@ protected Tuple Apply(TupleTransformType transformType, Tuple source1, Tuple sou
public override string ToString()
{
string description = $"{SourceCount}: {(SourceCount == 1 ? singleSourceMap.ToCommaDelimitedString() : map.ToCommaDelimitedString())}, {(isReadOnly ? Strings.ReadOnlyShort : Strings.ReadWriteShort)}";
return string.Format(Strings.TupleTransformFormat,
GetType().GetShortName(),
description);
return string.Format(Strings.TupleTransformFormat, GetType().Name, description);
}


Expand Down
4 changes: 1 addition & 3 deletions Orm/Xtensive.Orm/Tuples/Transform/SegmentTransform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ public Segment<int> Segment
public override string ToString()
{
string description = $"{segment}, {(IsReadOnly ? Strings.ReadOnlyShort : Strings.ReadWriteShort)}";
return string.Format(Strings.TupleTransformFormat,
GetType().GetShortName(),
description);
return string.Format(Strings.TupleTransformFormat, GetType().Name, description);
}


Expand Down
3 changes: 2 additions & 1 deletion Orm/Xtensive.Orm/Tuples/Transform/TupleTransformBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ public virtual bool IsReadOnly {
/// <inheritdoc/>
public override string ToString()
{
return GetType().GetShortName();
var type = GetType();
return type.IsGenericType ? type.GetShortName() : type.Name;
}
}
}