mirror of
https://github.com/smarty-php/smarty.git
synced 2025-10-18 15:05:19 +02:00
- optimization {foreach} compiler and processing
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user