Replace post increment with pre increment if we don't need the result.
authorLars Knoll <lars.knoll@digia.com>
Wed, 13 Feb 2013 21:27:15 +0000 (22:27 +0100)
committerSimon Hausmann <simon.hausmann@digia.com>
Thu, 14 Feb 2013 06:09:04 +0000 (07:09 +0100)
Same for decrement operations.

Change-Id: I9ef33f12f8cf009e9d441989dbc6bc6a233b8994
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
src/v4/qv4codegen.cpp

index 4ad7b69..9b9c931 100644 (file)
@@ -1567,9 +1567,13 @@ bool Codegen::visit(PostDecrementExpression *ast)
         throwReferenceError(ast->base->lastSourceLocation(), "Invalid left-hand side expression in postfix operation");
     throwSyntaxErrorOnEvalOrArgumentsInStrictMode(*expr, ast->decrementToken);
 
-    IR::ExprList *args = _function->New<IR::ExprList>();
-    args->init(*expr);
-    _expr.code = call(_block->NAME(IR::Name::builtin_postdecrement, ast->lastSourceLocation().startLine, ast->lastSourceLocation().startColumn), args);
+    if (_expr.accept(nx)) {
+        move(*expr, unop(IR::OpDecrement, *expr));
+    } else {
+        IR::ExprList *args = _function->New<IR::ExprList>();
+        args->init(*expr);
+        _expr.code = call(_block->NAME(IR::Name::builtin_postdecrement, ast->lastSourceLocation().startLine, ast->lastSourceLocation().startColumn), args);
+    }
     return false;
 }
 
@@ -1580,9 +1584,13 @@ bool Codegen::visit(PostIncrementExpression *ast)
         throwReferenceError(ast->base->lastSourceLocation(), "Invalid left-hand side expression in postfix operation");
     throwSyntaxErrorOnEvalOrArgumentsInStrictMode(*expr, ast->incrementToken);
 
-    IR::ExprList *args = _function->New<IR::ExprList>();
-    args->init(*expr);
-    _expr.code = call(_block->NAME(IR::Name::builtin_postincrement, ast->lastSourceLocation().startLine, ast->lastSourceLocation().startColumn), args);
+    if (_expr.accept(nx)) {
+        move(*expr, unop(IR::OpIncrement, *expr));
+    } else {
+        IR::ExprList *args = _function->New<IR::ExprList>();
+        args->init(*expr);
+        _expr.code = call(_block->NAME(IR::Name::builtin_postincrement, ast->lastSourceLocation().startLine, ast->lastSourceLocation().startColumn), args);
+    }
     return false;
 }