From 6ecbe6441f825489b5fafde1a274952933254c7f Mon Sep 17 00:00:00 2001 From: Erik Verbruggen Date: Thu, 21 Sep 2017 14:02:31 +0200 Subject: Improve while(true/false) condition generation Both in while-loops and in do-while-loops. Change-Id: I50be52e3ea6ecb9ce6886e6da03c35a1790a45e8 Reviewed-by: Simon Hausmann --- src/qml/compiler/qv4codegen.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'src/qml/compiler/qv4codegen.cpp') 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(ast->expression)) { + if (AST::cast(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(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(ast->expression)) + condition(ast->expression, &start, &end, true); start.link(); statement(ast->statement); -- cgit v1.2.3