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 <gpe@openrs2.dev>
bzip2
Graham 5 years ago
parent 5c1e630cb8
commit 0395224000
  1. 11
      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<LabelNode>()
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
}
}
changed = changed or tryCatchBlocks.removeIf {
it.start in deadLabels && it.end in deadLabels || it.isBodyEmpty()
}
changed = changed or tryCatchBlocks.removeIf { it.isBodyEmpty() }
} while (changed)
}

Loading…
Cancel
Save