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
This commit is contained in:
fabien
2009-10-12 12:12:29 +00:00
parent 71ee7ba1f7
commit 92bbc7ee40
+15 -3
View File
@@ -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(');