Skip to content
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

perf: Improve performance by introducing caches to hotspots #182

Merged
merged 1 commit into from
Jul 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
8 changes: 8 additions & 0 deletions src/dscom/TypeInfoResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ internal sealed class TypeInfoResolver : ITypeLibCache

private readonly Dictionary<Guid, ITypeInfo> _types = new();

private readonly Dictionary<Type, ITypeInfo?> _resolvedTypeInfos = new();

public WriterContext WriterContext { get; }

public TypeInfoResolver(WriterContext writerContext)
Expand Down Expand Up @@ -67,6 +69,11 @@ public TypeInfoResolver(WriterContext writerContext)

public ITypeInfo? ResolveTypeInfo(Type type)
{
if (_resolvedTypeInfos.TryGetValue(type, out var typeInfo))
{
return typeInfo;
}

ITypeInfo? retval;
if (type.FullName == "System.Collections.IEnumerator")
{
Expand Down Expand Up @@ -126,6 +133,7 @@ public TypeInfoResolver(WriterContext writerContext)
}
}
}
_resolvedTypeInfos[type] = retval;
return retval;
}

Expand Down
10 changes: 9 additions & 1 deletion src/dscom/writer/MethodWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,20 @@ protected virtual short GetParametersCount()
return retVal;
}

private bool? _isComVisible;

protected virtual bool IsComVisible
{
get
{
if (_isComVisible != null)
{
return _isComVisible.Value;
}

var methodAttribute = MethodInfo.GetCustomAttribute<ComVisibleAttribute>();
return methodAttribute == null || methodAttribute.Value;
_isComVisible = methodAttribute == null || methodAttribute.Value;
return _isComVisible.Value;
}
}

Expand Down
10 changes: 9 additions & 1 deletion src/dscom/writer/PropertyMethodWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,20 @@ public PropertyMethodWriter(InterfaceWriter interfaceWriter, MethodInfo methodIn
MemberInfo = _propertyInfo!;
}

private bool? _isComVisible;

protected override bool IsComVisible
{
get
{
if (_isComVisible != null)
{
return _isComVisible.Value;
}

var propertyAttribute = MemberInfo.GetCustomAttribute<ComVisibleAttribute>();
return (propertyAttribute == null || propertyAttribute.Value) && base.IsComVisible;
_isComVisible = (propertyAttribute == null || propertyAttribute.Value) && base.IsComVisible;
return _isComVisible.Value;
}
}

Expand Down
Loading