Skip to content

Commit

Permalink
Improve performance of ToMethodDescriptor
Browse files Browse the repository at this point in the history
  • Loading branch information
ds5678 committed Nov 21, 2024
1 parent decde80 commit 9440d53
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions Cpp2IL.Core/Utils/AsmResolver/ContextToMethodDescriptor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Linq;
using System.Linq;
using AsmResolver.DotNet;
using AsmResolver.DotNet.Signatures;
using Cpp2IL.Core.Model.Contexts;
Expand Down Expand Up @@ -26,27 +26,27 @@ private static MethodSignature ToMethodSignature(this MethodAnalysisContext cont

public static IMethodDescriptor ToMethodDescriptor(this MethodAnalysisContext context, ModuleDefinition parentModule)
{
if (context is ConcreteGenericMethodAnalysisContext concreteMethod)
return context is ConcreteGenericMethodAnalysisContext concreteMethod
? concreteMethod.ToMethodDescriptor(parentModule)
: parentModule.DefaultImporter.ImportMethod(context.GetMethodDefinition());
}

public static IMethodDescriptor ToMethodDescriptor(this ConcreteGenericMethodAnalysisContext context, ModuleDefinition parentModule)
{
var memberReference = new MemberReference(
context.DeclaringType?.ToTypeSignature(parentModule).ToTypeDefOrRef(),
context.Name,
context.BaseMethodContext.ToMethodSignature(parentModule));

var methodGenericParameters = context.ResolveMethodGenericParameters();
if (methodGenericParameters.Length == 0)
{
var memberReference = new MemberReference(
concreteMethod.DeclaringType?.ToTypeSignature(parentModule).ToTypeDefOrRef(),
concreteMethod.Name,
concreteMethod.BaseMethodContext.ToMethodSignature(parentModule));

var methodGenericParameters = concreteMethod.ResolveMethodGenericParameters();
if (methodGenericParameters.Length == 0)
{
return parentModule.DefaultImporter.ImportMethod(memberReference);
}
else
{
var typeSignatures = methodGenericParameters.Select(p => p.ToTypeSignature(parentModule)).ToArray();
return parentModule.DefaultImporter.ImportMethod(memberReference.MakeGenericInstanceMethod(typeSignatures));
}
return parentModule.DefaultImporter.ImportMethod(memberReference);
}
else
{
return parentModule.DefaultImporter.ImportMethod(context.GetMethodDefinition());
var typeSignatures = methodGenericParameters.Select(p => p.ToTypeSignature(parentModule)).ToArray();
return parentModule.DefaultImporter.ImportMethod(memberReference.MakeGenericInstanceMethod(typeSignatures));
}
}
}

0 comments on commit 9440d53

Please sign in to comment.