Use same heuristic in TernaryTransformer as IfElseTransformer

master
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) { public void transform(CompilationUnit unit) {
unit.findAll(ConditionalExpr.class).forEach(expr -> { unit.findAll(ConditionalExpr.class).forEach(expr -> {
var condition = expr.getCondition(); var condition = expr.getCondition();
if (!ExprUtils.isNot(condition)) { var notCondition = ExprUtils.not(condition);
if (ExprUtils.countNots(notCondition) >= ExprUtils.countNots(condition)) {
return; return;
} }
var thenExpr = expr.getThenExpr(); var thenExpr = expr.getThenExpr();
var elseExpr = expr.getElseExpr(); var elseExpr = expr.getElseExpr();
expr.setCondition(ExprUtils.not(condition)); expr.setCondition(notCondition);
expr.setThenExpr(elseExpr.clone()); expr.setThenExpr(elseExpr.clone());
expr.setElseExpr(thenExpr.clone()); expr.setElseExpr(thenExpr.clone());
}); });

Loading…
Cancel
Save