cvs: smarty / NEWS Smarty.class.php Smarty_Compiler.class.php /docs appendixes.sgml designers.sgml /plugins function.html_options.php
function.html_select_time.php

From: Date: Mon, 03 Jun 2002 16:05:33 +0000
Subject: cvs: smarty / NEWS Smarty.class.php Smarty_Compiler.class.php /docs appendixes.sgml designers.sgml /plugins function.html_options.php
function.html_select_time.php
Groups: php.smarty.cvs 
Request: Send a blank email to php-smarty-cvs+get-119@lists.php.net to get a copy of this message
mohrt Mon Jun 3 12:05:33 2002 EDT Modified files: /smarty NEWS Smarty.class.php Smarty_Compiler.class.php /smarty/docs appendixes.sgml designers.sgml /smarty/plugins function.html_options.php function.html_select_time.php Log: optimized for loops with count() function calls

Index: smarty/NEWS diff -u smarty/NEWS:1.200 smarty/NEWS:1.201 --- smarty/NEWS:1.200 Tue May 21 15:43:17 2002 +++ smarty/NEWS Mon Jun 3 12:05:32 2002 @@ -1,3 +1,4 @@ + - optimized for loops with count() function calls (monte) - add month_value_format attribute to html_select_date plugin (Gary Loescher, Monte) - made it possible to use simple variables inside [] for Index: smarty/Smarty.class.php diff -u smarty/Smarty.class.php:1.276 smarty/Smarty.class.php:1.277 --- smarty/Smarty.class.php:1.276 Thu May 16 12:15:49 2002 +++ smarty/Smarty.class.php Mon Jun 3 12:05:32 2002 @@ -1157,7 +1157,7 @@ $this->_config[1]['files'][$file] = true; } } else if ($scope == 'global') - for ($i = 1; $i < count($this->_config); $i++) { + for ($i = 1, $for_max = count($this->_config); $i < $for_max; $i++) { if (!isset($this->_config[$i]['files'][$file])) { $this->_config[$i]['vars'] = array_merge($this->_config[$i]['vars'], $this->_conf_obj->get($file)); $this->_config[$i]['files'][$file] = true; @@ -1170,7 +1170,7 @@ if (count($this->_config) > 0) $this->_config[1]['vars'] = array_merge($this->_config[1]['vars'], $this->_conf_obj->get($file, $section)); } else if ($scope == 'global') - for ($i = 1; $i < count($this->_config); $i++) + for ($i = 1, $for_max = count($this->_config); $i < $for_max; $i++) $this->_config[$i]['vars'] = array_merge($this->_config[$i]['vars'], $this->_conf_obj->get($file, $section)); } @@ -1194,7 +1194,7 @@ $results, $match); list($cached_inserts, $insert_args) = $match; - for ($i = 0; $i < count($cached_inserts); $i++) { + for ($i = 0, $for_max = count($cached_inserts); $i < $for_max; $i++) { if ($this->debugging) { $debug_start_time = $this->_get_microtime(); } Index: smarty/Smarty_Compiler.class.php diff -u smarty/Smarty_Compiler.class.php:1.115 smarty/Smarty_Compiler.class.php:1.116 --- smarty/Smarty_Compiler.class.php:1.115 Fri May 17 11:11:49 2002 +++ smarty/Smarty_Compiler.class.php Mon Jun 3 12:05:32 2002 @@ -110,11 +110,11 @@ $text_blocks = preg_split("!{$ldq}.*?{$rdq}!s", $template_source); /* loop through text blocks */ - for ($curr_tb = 0; $curr_tb < count($text_blocks); $curr_tb++) { + for ($curr_tb = 0, $for_max = count($text_blocks); $curr_tb < $for_max; $curr_tb++) { /* match anything within <? ?> */ if (preg_match_all('!(<\?[^?]*?\?>|<script\s+language\s*=\s*[\"\']?php[\"\']?\s*>)!is', $text_blocks[$curr_tb], $sp_match)) { /* found at least one match, loop through each one */ - for ($curr_sp = 0; $curr_sp < count($sp_match[0]); $curr_sp++) { + for ($curr_sp = 0, $for_max2 = count($sp_match[0]); $curr_sp < $for_max2; $curr_sp++) { if (preg_match('!^(<\?(php\s|\s|=\s)|<script\s*language\s*=\s*[\"\']?php[\"\']?\s*>)!is', $sp_match[0][$curr_sp])) { /* php tag */ if ($this->php_handling == SMARTY_PHP_PASSTHRU) { @@ -140,7 +140,7 @@ /* Compile the template tags into PHP code. */ $compiled_tags = array(); - for ($i = 0; $i < count($template_tags); $i++) { + for ($i = 0, $for_max = count($template_tags); $i < $for_max; $i++) { $this->_current_line_no += substr_count($text_blocks[$i], "\n"); $compiled_tags[] = $this->_compile_tag($template_tags[$i]); $this->_current_line_no += substr_count($template_tags[$i], "\n"); @@ -149,7 +149,7 @@ $template_compiled = ''; /* Interleave the compiled contents and text blocks to get the final result. */ - for ($i = 0; $i < count($compiled_tags); $i++) { + for ($i = 0, $for_max = count($compiled_tags); $i < $for_max; $i++) { $template_compiled .= $text_blocks[$i].$compiled_tags[$i]; } $template_compiled .= $text_blocks[$i]; @@ -159,7 +159,7 @@ $strip_tags = $match[0]; $strip_tags_modified = preg_replace("!{$ldq}/?strip{$rdq}|[\t ]+$|^[\t ]+!m", '', $strip_tags); $strip_tags_modified = preg_replace('![\r\n]+!m', '', $strip_tags_modified); - for ($i = 0; $i < count($strip_tags); $i++) + for ($i = 0, $for_max = count($strip_tags); $i < $for_max; $i++) $template_compiled = preg_replace("!{$ldq}strip{$rdq}.*?{$ldq}/strip{$rdq}!s", $this->quote_replace($strip_tags_modified[$i]), $template_compiled, 1); @@ -844,7 +844,7 @@ $is_arg_stack = array(); - for ($i = 0; $i < count($tokens); $i++) { + for ($i = 0, $for_max = count($tokens); $i < $for_max; $i++) { $token = &$tokens[$i]; switch ($token) { @@ -1219,7 +1219,7 @@ preg_match_all('!\|(@?\w+)((?>:(?:'. $qstr_regexp . '|[^|]+))*)!', '|' . $modifier_string, $match); list(, $modifiers, $modifier_arg_strings) = $match; - for ($i = 0; $i < count($modifiers); $i++) { + for ($i = 0, $for_max = count($modifiers); $i < $for_max; $i++) { $modifier_name = $modifiers[$i]; preg_match_all('!:(' . $qstr_regexp . '|[^:]+)!', $modifier_arg_strings[$i], $match); $modifier_args = $match[1]; Index: smarty/docs/appendixes.sgml diff -u smarty/docs/appendixes.sgml:1.7 smarty/docs/appendixes.sgml:1.8 --- smarty/docs/appendixes.sgml:1.7 Tue Mar 12 16:38:54 2002 +++ smarty/docs/appendixes.sgml Mon Jun 3 12:05:33 2002 @@ -400,7 +400,7 @@ <para> Smarty's homepage is located at http://www.phpinsider.com/php/code/Smarty/. You can join the mailing list by sending an e-mail to - subscribe-smarty@lists.ispi.net. An archive of the mailing list can be + smarty-general-subscribe@lists.php.net. An archive of the mailing list can be viewed at http://marc.theaimsgroup.com/?l=smarty&amp;r=1&amp;w=2 </para> </chapter> Index: smarty/docs/designers.sgml diff -u smarty/docs/designers.sgml:1.30 smarty/docs/designers.sgml:1.31 --- smarty/docs/designers.sgml:1.30 Tue May 21 15:41:33 2002 +++ smarty/docs/designers.sgml Mon Jun 3 12:05:33 2002 @@ -3737,6 +3737,16 @@ math function will be assigned to this template variable instead of being output to the template. </para> + <note> + <title>Technical Note</title> + <para> + math is an expensive function in performance due to its use of + the php eval() function. Doing the math in PHP is much more + efficient, so whenever possible do the math calculations in PHP + and assign the results to the template. Definately avoid + repetitive math function calls, like within section loops. + </para> + </note> <example> <title>math</title> <programlisting> Index: smarty/plugins/function.html_options.php diff -u smarty/plugins/function.html_options.php:1.2 smarty/plugins/function.html_options.php:1.3 --- smarty/plugins/function.html_options.php:1.2 Wed Feb 6 10:13:24 2002 +++ smarty/plugins/function.html_options.php Mon Jun 3 12:05:33 2002 @@ -29,7 +29,7 @@ } else { settype($output, 'array'); settype($values, 'array'); - for ($i = 0; $i < count($output); $i++) { + for ($i = 0, $for_max = count($output); $i < $for_max; $i++) { /* By default, check value against $selected */ $sel_check = $values[$i]; $html_result .= "<option"; Index: smarty/plugins/function.html_select_time.php diff -u smarty/plugins/function.html_select_time.php:1.4 smarty/plugins/function.html_select_time.php:1.5 --- smarty/plugins/function.html_select_time.php:1.4 Thu Mar 28 09:52:52 2002 +++ smarty/plugins/function.html_select_time.php Mon Jun 3 12:05:33 2002 @@ -37,7 +37,7 @@ if ($display_hours) { $hours = $use_24_hours ? range(0, 23) : range(1, 12); $hour_fmt = $use_24_hours ? '%H' : '%I'; - for ($i = 0; $i < count($hours); $i++) + for ($i = 0, $for_max = count($hours); $i < $for_max; $i++) $hours[$i] = sprintf('%02d', $hours[$i]); $html_result .= '<select name='; if (null !== $field_array) { @@ -55,7 +55,7 @@ if ($display_minutes) { $all_minutes = range(0, 59); - for ($i = 0; $i < count($all_minutes); $i+= $minute_interval) + for ($i = 0, $for_max = count($all_minutes); $i < $for_max; $i+= $minute_interval) $minutes[] = sprintf('%02d', $all_minutes[$i]); $selected = intval(floor(strftime('%M', $time) / $minute_interval) * $minute_interval); $html_result .= '<select name='; @@ -74,7 +74,7 @@ if ($display_seconds) { $all_seconds = range(0, 59); - for ($i = 0; $i < count($all_seconds); $i+= $second_interval) + for ($i = 0, $for_max = count($all_seconds); $i < $for_max; $i+= $second_interval) $seconds[] = sprintf('%02d', $all_seconds[$i]); $selected = intval(floor(strftime('%S', $time) / $second_interval) * $second_interval); $html_result .= '<select name=';
« previous php.smarty.cvs (#119) next »