optimize compiled code of {foreach}

This commit is contained in:
Uwe Tews
2015-02-15 16:58:42 +01:00
parent 8082bc7471
commit 464b37c053
3 changed files with 114 additions and 48 deletions
@@ -33,7 +33,9 @@ class Smarty_Internal_Compile_Private_Special_Variable extends Smarty_Internal_C
if (!isset($compiler->smarty->security_policy) || $compiler->smarty->security_policy->isTrustedSpecialSmartyVar($variable, $compiler)) {
switch ($variable) {
case 'foreach':
return "\$_smarty_tpl->getVariable('smarty')->value$parameter";
$name = trim($_index[1], "'");
$foreachVar = "'__foreach_{$name}'";
return "isset(\$_smarty_tpl->tpl_vars[$foreachVar]->value[{$_index[2]}]) ? \$_smarty_tpl->tpl_vars[$foreachVar]->value[{$_index[2]}] : null";
case 'section':
return "\$_smarty_tpl->getVariable('smarty')->value$parameter";
case 'capture':