From 555620887fb2e5488789c44679a9e36decb46f1a Mon Sep 17 00:00:00 2001 From: Graham Date: Sun, 25 Aug 2019 11:41:56 +0100 Subject: [PATCH] Use same heuristic in TernaryTransformer as IfElseTransformer --- .../dev/openrs2/deob/ast/transform/TernaryTransformer.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/TernaryTransformer.java b/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/TernaryTransformer.java index 5a466d4d75..08fd83c2cf 100644 --- a/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/TernaryTransformer.java +++ b/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()); });