diff options
author | Erik Verbruggen <erik.verbruggen@qt.io> | 2017-09-01 15:22:02 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2017-09-01 18:14:38 +0000 |
commit | a91383545c6f487cff61f401d11f1e85939222e9 (patch) | |
tree | 53069e2ca298325423c68b37939786fc5596eeea /src | |
parent | 55fcbce751e91944f7b2838bc75da592f99fdfef (diff) |
Generate a Decrement instead of a Sub with -1 as the rhs
Change-Id: Ie7f5f620089d58752d8f284293acda5794b4e99a
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/qml/compiler/qv4codegen.cpp | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/src/qml/compiler/qv4codegen.cpp b/src/qml/compiler/qv4codegen.cpp index cd07e47e15..872833bfd3 100644 --- a/src/qml/compiler/qv4codegen.cpp +++ b/src/qml/compiler/qv4codegen.cpp @@ -883,6 +883,7 @@ Codegen::Reference Codegen::binopHelper(QSOperator::Op oper, Reference &left, Re { switch (oper) { case QSOperator::Add: { + //### Todo: when we add type hints, we can generate an Increment when both the lhs is a number and the rhs == 1 left = left.storeOnStack(); right.loadInAccumulator(); Instruction::Add add; @@ -891,11 +892,16 @@ Codegen::Reference Codegen::binopHelper(QSOperator::Op oper, Reference &left, Re break; } case QSOperator::Sub: { - left = left.storeOnStack(); - right.loadInAccumulator(); - Instruction::Sub sub; - sub.lhs = left.stackSlot(); - bytecodeGenerator->addInstruction(sub); + if (right.isConst() && right.constant == Encode(int(1))) { + left.loadInAccumulator(); + bytecodeGenerator->addInstruction(Instruction::Decrement()); + } else { + left = left.storeOnStack(); + right.loadInAccumulator(); + Instruction::Sub sub; + sub.lhs = left.stackSlot(); + bytecodeGenerator->addInstruction(sub); + } break; } case QSOperator::Mul: { |