- optimization {foreach} compiler and processing

This commit is contained in:
uwetews
2016-05-16 17:57:06 +02:00
parent a62557e817
commit 0fcac38c70
4 changed files with 57 additions and 30 deletions

View File

@@ -38,24 +38,35 @@ class Smarty_Internal_Runtime_Foreach
$properties = array())
{
$saveVars = array();
if (isset($tpl->tpl_vars[ $item ])) {
$saveVars[ $item ] = $tpl->tpl_vars[ $item ];
}
if ($key) {
if (isset($tpl->tpl_vars[ $key ])) {
$saveVars[ $key ] = $tpl->tpl_vars[ $key ];
}
$tpl->tpl_vars[ $key ] = new Smarty_Variable(null, $tpl->isRenderingCache);
}
if (!is_array($from) && !is_object($from)) {
settype($from, 'array');
}
$total = $needTotal ? $this->count($from) : 1;
$tpl->tpl_vars[ $item ] = new Smarty_Variable(null, $tpl->isRenderingCache);
if ($needTotal) {
$tpl->tpl_vars[ $item ]->total = $total;
$total = ($needTotal || isset($properties[ 'total' ])) ? $this->count($from) : 1;
if (empty($from)) {
$from = null;
$total = 0;
if ($needTotal) {
if (isset($tpl->tpl_vars[ $item ])) {
$saveVars[ $item ] = $tpl->tpl_vars[ $item ];
}
$tpl->tpl_vars[ $item ] = new Smarty_Variable(null, $tpl->isRenderingCache);
$tpl->tpl_vars[ $item ]->total = 0;
}
} else {
if (isset($tpl->tpl_vars[ $item ])) {
$saveVars[ $item ] = $tpl->tpl_vars[ $item ];
}
if ($key) {
if (isset($tpl->tpl_vars[ $key ])) {
$saveVars[ $key ] = $tpl->tpl_vars[ $key ];
}
$tpl->tpl_vars[ $key ] = new Smarty_Variable(null, $tpl->isRenderingCache);
}
$tpl->tpl_vars[ $item ] = new Smarty_Variable(null, $tpl->isRenderingCache);
if ($needTotal) {
$tpl->tpl_vars[ $item ]->total = $total;
}
}
$tpl->tpl_vars[ $item ]->_loop = false;
if ($name) {
$namedVar = "__smarty_foreach_{$name}";
if (isset($tpl->tpl_vars[ $namedVar ])) {
@@ -77,7 +88,6 @@ class Smarty_Internal_Runtime_Foreach
$tpl->tpl_vars[ $namedVar ] = new Smarty_Variable($namedProp);
}
$this->stack[] = $saveVars;
return $from;
}