Add two tiny optimisations which make decompiled output easier to read

This commit is contained in:
Mumfrey committed 2015-12-16 14:09:23 +00:00
1 parent be78c8b191
commit 03422a0851
2 files changed
+35 -7

No files matched your search

@@ -405,7 +405,9 @@ public class CallbackInjector extends Injector {
}
}
this.createCallbackInfo(callback);
if (this.cancellable) {
this.createCallbackInfo(callback, true);
}
this.invokeCallback(callback, callbackMethod);
this.injectCancellationCode(callback);
@@ -489,15 +491,29 @@ public class CallbackInjector extends Injector {
/**
* @param callback callback handle
* @param store store the callback info in a local variable
*/
private void createCallbackInfo(final Callback callback) {
private void createCallbackInfo(final Callback callback, boolean store) {
this.dupReturnValue(callback);
callback.add(new TypeInsnNode(Opcodes.NEW, callback.target.callbackInfoClass), true, false);
callback.add(new TypeInsnNode(Opcodes.NEW, callback.target.callbackInfoClass), true, !store);
callback.add(new InsnNode(Opcodes.DUP), true, true);
this.invokeCallbackInfoCtor(callback);
callback.add(new VarInsnNode(Opcodes.ASTORE, callback.marshallVar));
if (store) {
callback.add(new VarInsnNode(Opcodes.ASTORE, callback.marshallVar));
}
}
/**
* @param callback callback handle
*/
private void loadOrCreateCallbackInfo(final Callback callback) {
if (this.cancellable) {
callback.add(new VarInsnNode(Opcodes.ALOAD, callback.marshallVar), false, true);
} else {
this.createCallbackInfo(callback, false);
}
}
/**
@@ -549,7 +565,7 @@ public class CallbackInjector extends Injector {
}
// Push the callback info onto the stack
callback.add(new VarInsnNode(Opcodes.ALOAD, callback.marshallVar), false, true);
this.loadOrCreateCallbackInfo(callback);
// (Maybe) push the locals onto the stack
if (callback.canCaptureLocals) {
@@ -242,6 +242,7 @@ public class MixinTargetContext implements IReferenceMapperContext {
this.validateMethod(method);
this.transformDescriptor(method);
AbstractInsnNode lastInsn = null;
for (Iterator<AbstractInsnNode> iter = method.instructions.iterator(); iter.hasNext();) {
AbstractInsnNode insn = iter.next();
@@ -250,12 +251,14 @@ public class MixinTargetContext implements IReferenceMapperContext {
} else if (insn instanceof FieldInsnNode) {
this.transformFieldRef(method, iter, new MemberRef.Field((FieldInsnNode)insn));
} else if (insn instanceof TypeInsnNode) {
this.transformTypeNode(method, iter, (TypeInsnNode)insn);
this.transformTypeNode(method, iter, (TypeInsnNode)insn, lastInsn);
} else if (insn instanceof LdcInsnNode) {
this.transformConstantNode(method, iter, (LdcInsnNode)insn);
} else if (insn instanceof InvokeDynamicInsnNode) {
this.transformInvokeDynamicNode(method, iter, (InvokeDynamicInsnNode)insn);
}
lastInsn = insn;
}
}
@@ -339,8 +342,17 @@ public class MixinTargetContext implements IReferenceMapperContext {
* @param method Method being processed
* @param iter Insn interator
* @param typeInsn Insn to transform
* @param lastNode Last insn in the method
*/
private void transformTypeNode(MethodNode method, Iterator<AbstractInsnNode> iter, TypeInsnNode typeInsn) {
private void transformTypeNode(MethodNode method, Iterator<AbstractInsnNode> iter, TypeInsnNode typeInsn, AbstractInsnNode lastNode) {
if (typeInsn.getOpcode() == Opcodes.CHECKCAST
&& typeInsn.desc.equals(this.targetClass.name)
&& lastNode.getOpcode() == Opcodes.ALOAD
&& ((VarInsnNode)lastNode).var == 0) {
iter.remove();
return;
}
if (typeInsn.desc.equals(this.getClassRef())) {
typeInsn.desc = this.targetClass.name;
}