From d753241ebbf6726878a45822de8bf1136353a26c Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Mon, 6 May 2013 15:11:10 +0200 Subject: [PATCH] Optimize resume after for loops by using + vs array_merge --- lib/Twig/Node/For.php | 2 +- test/Twig/Tests/Node/ForTest.php | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/Twig/Node/For.php b/lib/Twig/Node/For.php index 20e543c..d1ff371 100644 --- a/lib/Twig/Node/For.php +++ b/lib/Twig/Node/For.php @@ -107,6 +107,6 @@ class Twig_Node_For extends Twig_Node $compiler->write('unset($context[\'_seq\'], $context[\'_iterated\'], $context[\''.$this->getNode('key_target')->getAttribute('name').'\'], $context[\''.$this->getNode('value_target')->getAttribute('name').'\'], $context[\'_parent\'], $context[\'loop\']);'."\n"); // keep the values set in the inner context for variables defined in the outer context - $compiler->write("\$context = array_merge(\$_parent, array_intersect_key(\$context, \$_parent));\n"); + $compiler->write("\$context = array_intersect_key(\$context, \$_parent) + \$_parent;\n"); } } diff --git a/test/Twig/Tests/Node/ForTest.php b/test/Twig/Tests/Node/ForTest.php index f1093b7..21cc84e 100644 --- a/test/Twig/Tests/Node/ForTest.php +++ b/test/Twig/Tests/Node/ForTest.php @@ -70,7 +70,7 @@ foreach (\$context['_seq'] as \$context["key"] => \$context["item"]) { } \$_parent = \$context['_parent']; unset(\$context['_seq'], \$context['_iterated'], \$context['key'], \$context['item'], \$context['_parent'], \$context['loop']); -\$context = array_merge(\$_parent, array_intersect_key(\$context, \$_parent)); +\$context = array_intersect_key(\$context, \$_parent) + \$_parent; EOF ); @@ -113,7 +113,7 @@ foreach (\$context['_seq'] as \$context["k"] => \$context["v"]) { } \$_parent = \$context['_parent']; unset(\$context['_seq'], \$context['_iterated'], \$context['k'], \$context['v'], \$context['_parent'], \$context['loop']); -\$context = array_merge(\$_parent, array_intersect_key(\$context, \$_parent)); +\$context = array_intersect_key(\$context, \$_parent) + \$_parent; EOF ); @@ -146,7 +146,7 @@ foreach (\$context['_seq'] as \$context["k"] => \$context["v"]) { } \$_parent = \$context['_parent']; unset(\$context['_seq'], \$context['_iterated'], \$context['k'], \$context['v'], \$context['_parent'], \$context['loop']); -\$context = array_merge(\$_parent, array_intersect_key(\$context, \$_parent)); +\$context = array_intersect_key(\$context, \$_parent) + \$_parent; EOF ); @@ -194,7 +194,7 @@ if (!\$context['_iterated']) { } \$_parent = \$context['_parent']; unset(\$context['_seq'], \$context['_iterated'], \$context['k'], \$context['v'], \$context['_parent'], \$context['loop']); -\$context = array_merge(\$_parent, array_intersect_key(\$context, \$_parent)); +\$context = array_intersect_key(\$context, \$_parent) + \$_parent; EOF ); -- 1.7.2.5