From f9f0401ec8997dcfac77104124e4204ebf801452 Mon Sep 17 00:00:00 2001 From: andrei Date: Thu, 13 Jun 2002 20:14:46 +0000 Subject: [PATCH] Optimize the calculation of section 'total' property. --- Smarty_Compiler.class.php | 10 +++++++--- libs/Smarty_Compiler.class.php | 10 +++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/Smarty_Compiler.class.php b/Smarty_Compiler.class.php index 3b5ea02d..ae16cba6 100644 --- a/Smarty_Compiler.class.php +++ b/Smarty_Compiler.class.php @@ -714,9 +714,13 @@ class Smarty_Compiler extends Smarty { " {$section_props}['start'] = min({$section_props}['start'], {$section_props}['step'] > 0 ? {$section_props}['loop'] : {$section_props}['loop']-1);\n"; } - $output .= "if ({$section_props}['show']) {\n" . - " {$section_props}['total'] = min(ceil(({$section_props}['step'] > 0 ? {$section_props}['loop'] - {$section_props}['start'] : {$section_props}['start']+1)/abs({$section_props}['step'])), {$section_props}['max']);\n" . - " if ({$section_props}['total'] == 0)\n" . + $output .= "if ({$section_props}['show']) {\n"; + if (!isset($attrs['start']) && !isset($attrs['step']) && !isset($attrs['max'])) { + $output .= " {$section_props}['total'] = {$section_props}['loop'];\n"; + } else { + $output .= " {$section_props}['total'] = min(ceil(({$section_props}['step'] > 0 ? {$section_props}['loop'] - {$section_props}['start'] : {$section_props}['start']+1)/abs({$section_props}['step'])), {$section_props}['max']);\n"; + } + $output .= " if ({$section_props}['total'] == 0)\n" . " {$section_props}['show'] = false;\n" . "} else\n" . " {$section_props}['total'] = 0;\n"; diff --git a/libs/Smarty_Compiler.class.php b/libs/Smarty_Compiler.class.php index 3b5ea02d..ae16cba6 100644 --- a/libs/Smarty_Compiler.class.php +++ b/libs/Smarty_Compiler.class.php @@ -714,9 +714,13 @@ class Smarty_Compiler extends Smarty { " {$section_props}['start'] = min({$section_props}['start'], {$section_props}['step'] > 0 ? {$section_props}['loop'] : {$section_props}['loop']-1);\n"; } - $output .= "if ({$section_props}['show']) {\n" . - " {$section_props}['total'] = min(ceil(({$section_props}['step'] > 0 ? {$section_props}['loop'] - {$section_props}['start'] : {$section_props}['start']+1)/abs({$section_props}['step'])), {$section_props}['max']);\n" . - " if ({$section_props}['total'] == 0)\n" . + $output .= "if ({$section_props}['show']) {\n"; + if (!isset($attrs['start']) && !isset($attrs['step']) && !isset($attrs['max'])) { + $output .= " {$section_props}['total'] = {$section_props}['loop'];\n"; + } else { + $output .= " {$section_props}['total'] = min(ceil(({$section_props}['step'] > 0 ? {$section_props}['loop'] - {$section_props}['start'] : {$section_props}['start']+1)/abs({$section_props}['step'])), {$section_props}['max']);\n"; + } + $output .= " if ({$section_props}['total'] == 0)\n" . " {$section_props}['show'] = false;\n" . "} else\n" . " {$section_props}['total'] = 0;\n";