From 0395224000648b4ec257e390948ad4319175b505 Mon Sep 17 00:00:00 2001 From: Graham Date: Fri, 10 Apr 2020 16:26:03 +0100 Subject: [PATCH] Simplify removeDeadCode() I think relying on just the isBodyEmpty() check is more correct too, as the end label of a try/catch is exclusive. Furthermore, we don't want to delete try/catch nodes where the middle of the body is not dead (even if the start and end are dead). Signed-off-by: Graham --- .../main/java/dev/openrs2/asm/MethodNodeUtils.kt | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/asm/src/main/java/dev/openrs2/asm/MethodNodeUtils.kt b/asm/src/main/java/dev/openrs2/asm/MethodNodeUtils.kt index 89b99aeb..fddb3a90 100644 --- a/asm/src/main/java/dev/openrs2/asm/MethodNodeUtils.kt +++ b/asm/src/main/java/dev/openrs2/asm/MethodNodeUtils.kt @@ -108,25 +108,18 @@ fun MethodNode.removeDeadCode(owner: String) { val analyzer = Analyzer(BasicInterpreter()) val frames = analyzer.analyze(owner, this) - val deadLabels = mutableSetOf() val it = instructions.iterator() var i = 0 for (insn in it) { - if (frames[i++] != null) { + if (frames[i++] != null || insn is LabelNode) { continue } - if (insn is LabelNode) { - deadLabels.add(insn) - } else { - it.remove() - changed = true - } + it.remove() + changed = true } - changed = changed or tryCatchBlocks.removeIf { - it.start in deadLabels && it.end in deadLabels || it.isBodyEmpty() - } + changed = changed or tryCatchBlocks.removeIf { it.isBodyEmpty() } } while (changed) }