summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShockah <me@shockah.pl>2022-02-09 21:10:20 +0100
committerShockah <me@shockah.pl>2022-02-09 21:10:20 +0100
commitd9599a3a0af500438fa71addb1a25d4608aefda5 (patch)
treee00352d085ce4959405ebf06cc08253890378c5c
parent354527bb810d06f69f2a8c45d1a23f294d228caf (diff)
downloadSMAPI-d9599a3a0af500438fa71addb1a25d4608aefda5.tar.gz
SMAPI-d9599a3a0af500438fa71addb1a25d4608aefda5.tar.bz2
SMAPI-d9599a3a0af500438fa71addb1a25d4608aefda5.zip
simplifies proxy method IL a bit
-rw-r--r--src/SMAPI/Framework/Reflection/InterfaceProxyBuilder.cs32
1 files 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);
}
}