From 2e84b179a001561b8e1bf99eb1c3647f5b07275b Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 14 Apr 2010 12:05:33 +0200 Subject: [PATCH] optimized for loop generation --- lib/Twig/Node/For.php | 9 +++------ 1 files changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/Twig/Node/For.php b/lib/Twig/Node/For.php index 2d115ea..50b0408 100644 --- a/lib/Twig/Node/For.php +++ b/lib/Twig/Node/For.php @@ -50,8 +50,6 @@ class Twig_Node_For extends Twig_Node implements Twig_NodeListInterface public function compile($compiler) { - static $i = 0; - $compiler ->addDebugInfo($this) ->pushContext() @@ -71,9 +69,8 @@ class Twig_Node_For extends Twig_Node implements Twig_NodeListInterface $loopVars = array('_key', $this->item->getName()); } - $var = $i++; $compiler - ->write("\$seq$var = twig_iterator_to_array(") + ->write("\$context['_seq'] = twig_iterator_to_array(") ->subcompile($this->seq) ->raw(");\n") ; @@ -81,7 +78,7 @@ class Twig_Node_For extends Twig_Node implements Twig_NodeListInterface if ($this->withLoop) { $compiler - ->write("\$length = count(\$seq$var);\n") + ->write("\$length = count(\$context['_seq']);\n") ->write("\$context['loop'] = array(\n") ->write(" 'parent' => \$context['_parent'],\n") @@ -97,7 +94,7 @@ class Twig_Node_For extends Twig_Node implements Twig_NodeListInterface } $compiler - ->write("foreach (\$seq$var as \$context[") + ->write("foreach (\$context['_seq'] as \$context[") ->repr($loopVars[0]) ->raw("] => \$context[") ->repr($loopVars[1]) -- 1.7.2.5