From b7ef6f0597f459e861516793532cda0f807c287b Mon Sep 17 00:00:00 2001 From: rodneyrehm Date: Fri, 7 Oct 2011 14:05:26 +0000 Subject: [PATCH] - improvement removed some unnecessary count()s --- change_log.txt | 1 + libs/plugins/block.textformat.php | 15 ++++++++------- libs/plugins/function.mailto.php | 9 +++------ libs/plugins/modifiercompiler.default.php | 6 ++++-- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/change_log.txt b/change_log.txt index 21d9c6e0..2164a66e 100644 --- a/change_log.txt +++ b/change_log.txt @@ -5,6 +5,7 @@ - improvement testInstall() now showing resolved paths and checking the include_path if necessary - bugfix html_options plugin did not handle object values properly (Issue #49, Forum Topic 20049) - improvement html_checkboxes and html_radios to accept null- and object values, and label_ids attribute +- improvement removed some unnecessary count()s 06.10.2011 - bugfix switch lexer internals depending on mbstring.func_overload diff --git a/libs/plugins/block.textformat.php b/libs/plugins/block.textformat.php index 4e5e80e8..bdd80673 100644 --- a/libs/plugins/block.textformat.php +++ b/libs/plugins/block.textformat.php @@ -78,26 +78,27 @@ function smarty_block_textformat($params, $content, $template, &$repeat) $_paragraphs = preg_split('![\r\n]{2}!', $content); $_output = ''; - for ($_x = 0, $_y = count($_paragraphs); $_x < $_y; $_x++) { - if ($_paragraphs[$_x] == '') { + + foreach ($_paragraphs as &$_paragraph) { + if (!$_paragraph) { continue; } // convert mult. spaces & special chars to single space - $_paragraphs[$_x] = preg_replace(array('!\s+!u', '!(^\s+)|(\s+$)!u'), array(' ', ''), $_paragraphs[$_x]); + $_paragraph = preg_replace(array('!\s+!u', '!(^\s+)|(\s+$)!u'), array(' ', ''), $_paragraph); // indent first line if ($indent_first > 0) { - $_paragraphs[$_x] = str_repeat($indent_char, $indent_first) . $_paragraphs[$_x]; + $_paragraph = str_repeat($indent_char, $indent_first) . $_paragraph; } // wordwrap sentences if (SMARTY_MBSTRING /* ^phpunit */&&empty($_SERVER['SMARTY_PHPUNIT_DISABLE_MBSTRING'])/* phpunit$ */) { require_once(SMARTY_PLUGINS_DIR . 'shared.mb_wordwrap.php'); - $_paragraphs[$_x] = smarty_mb_wordwrap($_paragraphs[$_x], $wrap - $indent, $wrap_char, $wrap_cut); + $_paragraph = smarty_mb_wordwrap($_paragraph, $wrap - $indent, $wrap_char, $wrap_cut); } else { - $_paragraphs[$_x] = wordwrap($_paragraphs[$_x], $wrap - $indent, $wrap_char, $wrap_cut); + $_paragraph = wordwrap($_paragraph, $wrap - $indent, $wrap_char, $wrap_cut); } // indent lines if ($indent > 0) { - $_paragraphs[$_x] = preg_replace('!^!m', str_repeat($indent_char, $indent), $_paragraphs[$_x]); + $_paragraph = preg_replace('!^!m', str_repeat($indent_char, $indent), $_paragraph); } } $_output = implode($wrap_char . $wrap_char, $_paragraphs); diff --git a/libs/plugins/function.mailto.php b/libs/plugins/function.mailto.php index c8e18fc6..c61cf2df 100644 --- a/libs/plugins/function.mailto.php +++ b/libs/plugins/function.mailto.php @@ -88,13 +88,10 @@ function smarty_function_mailto($params, $template) } } - $mail_parm_vals = ''; - for ($i = 0, $_length = count($mail_parms); $i < $_length; $i++) { - $mail_parm_vals .= (0 == $i) ? '?' : '&'; - $mail_parm_vals .= $mail_parms[$i]; + if ($mail_parms) { + $address .= '?' . join('&', $mail_parms); } - $address .= $mail_parm_vals; - + $encode = (empty($params['encode'])) ? 'none' : $params['encode']; if (!isset($_allowed_encoding[$encode])) { trigger_error("mailto: 'encode' parameter must be none, javascript, javascript_charcode or hex", E_USER_WARNING); diff --git a/libs/plugins/modifiercompiler.default.php b/libs/plugins/modifiercompiler.default.php index 93635228..4f831a58 100644 --- a/libs/plugins/modifiercompiler.default.php +++ b/libs/plugins/modifiercompiler.default.php @@ -24,8 +24,10 @@ function smarty_modifiercompiler_default ($params, $compiler) if (!isset($params[1])) { $params[1] = "''"; } - for ($i = 1, $cnt = count($params); $i < $cnt; $i++) { - $output = '(($tmp = @' . $output . ')===null||$tmp===\'\' ? ' . $params[$i] . ' : $tmp)'; + + array_shift($params); + foreach ($params as $param) { + $output = '(($tmp = @' . $output . ')===null||$tmp===\'\' ? ' . $param . ' : $tmp)'; } return $output; }