From 92bbc7ee405f5635f4647040d883dbd77d1ac7da Mon Sep 17 00:00:00 2001 From: fabien Date: Mon, 12 Oct 2009 12:12:29 +0000 Subject: [PATCH] made a small optimization to for loop when no else clause exists git-svn-id: http://svn.twig-project.org/trunk@32 93ef8e89-cb99-4229-a87c-7fa0fa45744b --- lib/Twig/Node/For.php | 18 +++++++++++++++--- 1 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/Twig/Node/For.php b/lib/Twig/Node/For.php index 5c2449e..e6d8482 100644 --- a/lib/Twig/Node/For.php +++ b/lib/Twig/Node/For.php @@ -51,16 +51,28 @@ class Twig_Node_For extends Twig_Node implements Twig_NodeListInterface $compiler ->addDebugInfo($this) ->pushContext() - ->write("\$context['_iterated'] = false;\n") + ; + + if (!is_null($this->else)) + { + $compiler->write("\$context['_iterated'] = false;\n"); + } + + $compiler ->write('foreach (twig_iterate($context, ') ->subcompile($this->seq) ->raw(") as \$iterator)\n") ->write("{\n") ->indent() - ->write("\$context['_iterated'] = true;\n") - ->write('twig_set_loop_context($context, $iterator, '); ; + if (!is_null($this->else)) + { + $compiler->write("\$context['_iterated'] = true;\n"); + } + + $compiler->write('twig_set_loop_context($context, $iterator, '); + if ($this->isMultitarget) { $compiler->raw('array('); -- 1.7.2.5