diff options
author | Erik Verbruggen <erik.verbruggen@qt.io> | 2017-09-21 14:02:31 +0200 |
---|---|---|
committer | Erik Verbruggen <erik.verbruggen@qt.io> | 2017-09-26 08:12:46 +0000 |
commit | 6ecbe6441f825489b5fafde1a274952933254c7f (patch) | |
tree | f24ceab85f6919af94c3e8c0b24359345c191f31 /src | |
parent | 1488ce8b9113171290107ceab7ffdd475ccc316f (diff) |
Improve while(true/false) condition generation
Both in while-loops and in do-while-loops.
Change-Id: I50be52e3ea6ecb9ce6886e6da03c35a1790a45e8
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/qml/compiler/qv4codegen.cpp | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/qml/compiler/qv4codegen.cpp b/src/qml/compiler/qv4codegen.cpp index 3fa422a579..824cb77e7a 100644 --- a/src/qml/compiler/qv4codegen.cpp +++ b/src/qml/compiler/qv4codegen.cpp @@ -2273,7 +2273,13 @@ bool Codegen::visit(DoWhileStatement *ast) statement(ast->statement); cond.link(); - condition(ast->expression, &body, &end, false); + + if (!AST::cast<FalseLiteral *>(ast->expression)) { + if (AST::cast<TrueLiteral *>(ast->expression)) + bytecodeGenerator->jump().link(body); + else + condition(ast->expression, &body, &end, false); + } end.link(); @@ -2718,6 +2724,9 @@ bool Codegen::visit(WhileStatement *ast) if (hasError) return true; + if (AST::cast<FalseLiteral *>(ast->expression)) + return false; + RegisterScope scope(this); BytecodeGenerator::Label start = bytecodeGenerator->newLabel(); @@ -2725,7 +2734,8 @@ bool Codegen::visit(WhileStatement *ast) BytecodeGenerator::Label cond = bytecodeGenerator->label(); ControlFlowLoop flow(this, &end, &cond); - condition(ast->expression, &start, &end, true); + if (!AST::cast<TrueLiteral *>(ast->expression)) + condition(ast->expression, &start, &end, true); start.link(); statement(ast->statement); |