Skip to content

Commit

Permalink
perf: Improve performance by introducing caches to hotspots (#182)
Browse files Browse the repository at this point in the history
Co-authored-by: spkl <spkl>
  • Loading branch information
spkl authored Jul 16, 2023
1 parent 426d817 commit 19c9471
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
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

0 comments on commit 19c9471

Please sign in to comment.