From d9599a3a0af500438fa71addb1a25d4608aefda5 Mon Sep 17 00:00:00 2001 From: Shockah Date: Wed, 9 Feb 2022 21:10:20 +0100 Subject: simplifies proxy method IL a bit --- .../Framework/Reflection/InterfaceProxyBuilder.cs | 32 +++++++--------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/src/SMAPI/Framework/Reflection/InterfaceProxyBuilder.cs b/src/SMAPI/Framework/Reflection/InterfaceProxyBuilder.cs index 1b6bf1d6..5e0dd838 100644 --- a/src/SMAPI/Framework/Reflection/InterfaceProxyBuilder.cs +++ b/src/SMAPI/Framework/Reflection/InterfaceProxyBuilder.cs @@ -247,28 +247,16 @@ namespace StardewModdingAPI.Framework.Reflection { ILGenerator il = methodBuilder.GetILGenerator(); - void EmitCallInstance() + var resultLocal = il.DeclareLocal(typeof(object)); // we store both unmodified and modified in here, hence `object` + il.Emit(OpCodes.Ldarg_0); + il.Emit(OpCodes.Ldfld, instanceField); + for (int i = 0; i < argTypes.Length; i++) + il.Emit(OpCodes.Ldarg, i + 1); + il.Emit(OpCodes.Callvirt, target); + il.Emit(OpCodes.Stloc, resultLocal); + + if (returnValueProxyTypeName != null) { - // load target instance - il.Emit(OpCodes.Ldarg_0); - il.Emit(OpCodes.Ldfld, instanceField); - - // invoke target method on instance - for (int i = 0; i < argTypes.Length; i++) - il.Emit(OpCodes.Ldarg, i + 1); - il.Emit(OpCodes.Callvirt, target); - } - - if (returnValueProxyTypeName == null) - { - EmitCallInstance(); - } - else - { - var resultLocal = il.DeclareLocal(typeof(object)); // we store both unmodified and modified in here - EmitCallInstance(); - il.Emit(OpCodes.Stloc, resultLocal); - // if (unmodifiedResultLocal == null) jump var isNullLabel = il.DefineLabel(); il.Emit(OpCodes.Ldloc, resultLocal); @@ -282,10 +270,10 @@ namespace StardewModdingAPI.Framework.Reflection il.Emit(OpCodes.Stloc, resultLocal); il.MarkLabel(isNullLabel); - il.Emit(OpCodes.Ldloc, resultLocal); } // return result + il.Emit(OpCodes.Ldloc, resultLocal); il.Emit(OpCodes.Ret); } } -- cgit