Use same heuristic in TernaryTransformer as IfElseTransformer

bzip2
Graham 5 years ago
parent f742aba80d
commit 555620887f
  1. 5
      deob-ast/src/main/java/dev/openrs2/deob/ast/transform/TernaryTransformer.java

@ -9,14 +9,15 @@ public final class TernaryTransformer extends Transformer {
public void transform(CompilationUnit unit) {
unit.findAll(ConditionalExpr.class).forEach(expr -> {
var condition = expr.getCondition();
if (!ExprUtils.isNot(condition)) {
var notCondition = ExprUtils.not(condition);
if (ExprUtils.countNots(notCondition) >= ExprUtils.countNots(condition)) {
return;
}
var thenExpr = expr.getThenExpr();
var elseExpr = expr.getElseExpr();
expr.setCondition(ExprUtils.not(condition));
expr.setCondition(notCondition);
expr.setThenExpr(elseExpr.clone());
expr.setElseExpr(thenExpr.clone());
});

Loading…
Cancel
Save