Skip to content

Commit cc4bd1f

Browse files
committed
Добавлена оптимация выражений с побитовым сдвигом
1 parent 865fe46 commit cc4bd1f

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/main/java/com/annimon/ownlang/parser/optimization/ExpressionSimplification.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,14 @@ public Node visit(BinaryExpression s, Void t) {
117117
return new ValueExpression(0);
118118
}
119119

120+
// x >> 0 to x, x << 0 to x
121+
if (isIntegerValue(s.expr2, 0) &&
122+
(s.operation == BinaryExpression.Operator.LSHIFT ||
123+
s.operation == BinaryExpression.Operator.RSHIFT)) {
124+
simplificationsCount++;
125+
return s.expr1;
126+
}
127+
120128
return super.visit(s, t);
121129
}
122130

0 commit comments

Comments
 (0)