From 5704e90423361cfc61d007fb74dd3b399e3c55f7 Mon Sep 17 00:00:00 2001 From: de4dot Date: Wed, 25 Jan 2012 12:19:45 +0100 Subject: [PATCH] Allow inlining value type methods --- blocks/cflow/MethodCallInlinerBase.cs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/blocks/cflow/MethodCallInlinerBase.cs b/blocks/cflow/MethodCallInlinerBase.cs index e07c2cb6..7ac0928a 100644 --- a/blocks/cflow/MethodCallInlinerBase.cs +++ b/blocks/cflow/MethodCallInlinerBase.cs @@ -106,8 +106,14 @@ namespace de4dot.blocks.cflow { if (methodArgs.Count - popLastArgs != calledMethodArgs.Count) return false; for (int i = 0; i < calledMethodArgs.Count; i++) { - if (!isCompatibleType(calledMethodArgs[i], methodArgs[i])) - return false; + var calledMethodArg = calledMethodArgs[i]; + var methodArg = methodArgs[i]; + if (!isCompatibleType(calledMethodArg, methodArg)) { + if (i != 0 || !calledMethod.HasImplicitThis) + return false; + if (!isCompatibleValueThisPtr(calledMethodArg, methodArg)) + return false; + } } instr = DotNetUtils.getInstruction(methodToInline.Body.Instructions, ref instrIndex); @@ -163,5 +169,14 @@ namespace de4dot.blocks.cflow { protected virtual bool isCompatibleType(TypeReference origType, TypeReference newType) { return MemberReferenceHelper.compareTypes(origType, newType); } + + static bool isCompatibleValueThisPtr(TypeReference origType, TypeReference newType) { + var newByRef = newType as ByReferenceType; + if (newByRef == null) + return false; + if (!newByRef.ElementType.IsValueType || !origType.IsValueType) + return false; + return MemberReferenceHelper.compareTypes(origType, newByRef.ElementType); + } } }