diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/callback/CallbackInjector.java b/src/main/java/org/spongepowered/asm/mixin/injection/callback/CallbackInjector.java index cf6288a8..2071c5cd 100644 --- a/src/main/java/org/spongepowered/asm/mixin/injection/callback/CallbackInjector.java +++ b/src/main/java/org/spongepowered/asm/mixin/injection/callback/CallbackInjector.java @@ -140,6 +140,13 @@ public class CallbackInjector extends Injector { * two purposes because they don't exist at the same time). */ final int marshallVar; + + /** + * True if this callback expects the target method arguments to be + * passed in. Set to false if {@link #checkDescriptor} determines that + * the "simple" descriptor matches. + */ + private boolean captureArgs = true; Callback(MethodNode handler, Target target, final AbstractInsnNode node, final LocalVariableNode[] locals, boolean captureLocals) { this.handler = handler; @@ -225,6 +232,11 @@ public class CallbackInjector extends Injector { return true; // Descriptor matches exactly, this is good } + if (this.target.getSimpleCallbackDescriptor().equals(desc) && !this.canCaptureLocals) { + this.captureArgs = false; + return true; + } + if (this.extraArgs > 0) { Type[] inTypes = Type.getArgumentTypes(desc); Type[] myTypes = Type.getArgumentTypes(this.descl); @@ -259,6 +271,10 @@ public class CallbackInjector extends Injector { return false; } + + boolean captureArgs() { + return this.captureArgs; + } } private final Logger logger = LogManager.getLogger("mixin"); @@ -528,7 +544,9 @@ public class CallbackInjector extends Injector { } // Push the target method's parameters onto the stack - ASMHelper.loadArgs(callback.target.arguments, callback, this.isStatic ? 0 : 1); + if (callback.captureArgs()) { + ASMHelper.loadArgs(callback.target.arguments, callback, this.isStatic ? 0 : 1); + } // Push the callback info onto the stack callback.add(new VarInsnNode(Opcodes.ALOAD, callback.marshallVar), false, true); diff --git a/src/main/java/org/spongepowered/asm/mixin/injection/struct/Target.java b/src/main/java/org/spongepowered/asm/mixin/injection/struct/Target.java index 8ebb2744..210a36ea 100644 --- a/src/main/java/org/spongepowered/asm/mixin/injection/struct/Target.java +++ b/src/main/java/org/spongepowered/asm/mixin/injection/struct/Target.java @@ -219,6 +219,15 @@ public class Target { return argIndices; } + /** + * Get "simple" callback descriptor (descriptor with only CallbackInfo) + * + * @return generated descriptor + */ + public String getSimpleCallbackDescriptor() { + return String.format("(L%s;)V", this.callbackInfoClass); + } + /** * Get the callback descriptor *