diff options
Diffstat (limited to 'modules/gdscript/gd_parser.cpp')
-rw-r--r-- | modules/gdscript/gd_parser.cpp | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/modules/gdscript/gd_parser.cpp b/modules/gdscript/gd_parser.cpp index b6e8478846..4b0164d8a2 100644 --- a/modules/gdscript/gd_parser.cpp +++ b/modules/gdscript/gd_parser.cpp @@ -1779,6 +1779,20 @@ void GDParser::_parse_block(BlockNode *p_block,bool p_static) { return; } + // Little optimisation for common usage "for i in range(...):": + // don't create and initialize a possibly huge array as range() + // would do, but instead create an iterator using xrange() + if (container->type == Node::TYPE_OPERATOR) { + OperatorNode *op = static_cast<OperatorNode *>(container); + if (op->arguments.size() > 0 && + op->arguments[0]->type == Node::TYPE_BUILT_IN_FUNCTION) { + BuiltInFunctionNode *c = static_cast<BuiltInFunctionNode *>(op->arguments[0]); + if (c->function == GDFunctions::GEN_RANGE) { + c->function = GDFunctions::GEN_XRANGE; + } + } + } + ControlFlowNode *cf_for = alloc_node<ControlFlowNode>(); cf_for->cf_type=ControlFlowNode::CF_FOR; @@ -1790,7 +1804,7 @@ void GDParser::_parse_block(BlockNode *p_block,bool p_static) { p_block->sub_blocks.push_back(cf_for->body); if (!_enter_indent_block(cf_for->body)) { - _set_error("Expected indented block after 'while'"); + _set_error("Expected indented block after 'for'"); p_block->end_line=tokenizer->get_token_line(); return; } |