From: fabien Date: Mon, 12 Oct 2009 12:12:29 +0000 (+0000) Subject: made a small optimization to for loop when no else clause exists X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=92bbc7ee405f5635f4647040d883dbd77d1ac7da;p=konrad%2Ftwig.git 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 --- 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(');