- improvement do not compute total property in {foreach} if not needed https://github.com/smarty-php/smarty/issues/443

This commit is contained in:
Uwe Tews
2018-05-17 06:27:35 +02:00
parent 115e178884
commit 514d99beaa
3 changed files with 8 additions and 4 deletions

View File

@@ -1,5 +1,6 @@
===== 3.1.33-dev-2 ===== ===== 3.1.33-dev-3 =====
17.05.2018 17.05.2018
- improvement do not compute total property in {foreach} if not needed https://github.com/smarty-php/smarty/issues/443
- bugfix plugins may not be loaded when setMergeCompiledIncludes is true https://github.com/smarty-php/smarty/issues/435 - bugfix plugins may not be loaded when setMergeCompiledIncludes is true https://github.com/smarty-php/smarty/issues/435
26.04.2018 26.04.2018

View File

@@ -112,7 +112,7 @@ class Smarty extends Smarty_Internal_TemplateBase
/** /**
* smarty version * smarty version
*/ */
const SMARTY_VERSION = '3.1.33-dev-2'; const SMARTY_VERSION = '3.1.33-dev-3';
/** /**
* define variable scopes * define variable scopes
*/ */

View File

@@ -37,17 +37,20 @@ class Smarty_Internal_Runtime_Foreach
public function init(Smarty_Internal_Template $tpl, $from, $item, $needTotal = false, $key = null, $name = null, public function init(Smarty_Internal_Template $tpl, $from, $item, $needTotal = false, $key = null, $name = null,
$properties = array()) $properties = array())
{ {
$needTotal = $needTotal || isset($properties[ 'total' ]);
$saveVars = array(); $saveVars = array();
$total = null; $total = null;
if (!is_array($from)) { if (!is_array($from)) {
if (is_object($from)) { if (is_object($from)) {
if ($needTotal) {
$total = $this->count($from); $total = $this->count($from);
}
} else { } else {
settype($from, 'array'); settype($from, 'array');
} }
} }
if (!isset($total)) { if (!isset($total)) {
$total = empty($from) ? 0 : (($needTotal || isset($properties[ 'total' ])) ? count($from) : 1); $total = empty($from) ? 0 : ($needTotal ? count($from) : 1);
} }
if (isset($tpl->tpl_vars[ $item ])) { if (isset($tpl->tpl_vars[ $item ])) {
$saveVars[ 'item' ] = array($item, $saveVars[ 'item' ] = array($item,