Suggestion for the outputfilter.trimwhitespace.php plugin

From: Date: Fri, 02 Jan 2004 04:39:08 +0000
Subject: Suggestion for the outputfilter.trimwhitespace.php plugin
Groups: php.smarty.dev 
Request: Send a blank email to php-smarty-dev+get-2013@lists.php.net to get a copy of this message
I made some modifications, in an attempt to enhance its performance. This is against the copy that came with Smarty 2.6.0 in my CVS repository. 1. If there isn't anything in $replace, dont bother to continue 2. Get a count on the elements of $replace for the for() loop, so the plugin only has to use count() once. This is merely a suggestion. Thanks ----- bash-2.05b$ cvs diff -u -r 1.2 outputfilter.trimwhitespace.php Index: outputfilter.trimwhitespace.php =================================================================== RCS file: /cvs/mpn2/includes/class/smarty/plugins/ outputfilter.trimwhitespace.php,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- outputfilter.trimwhitespace.php 11 Dec 2003 23:00:08 -0000 1.2 +++ outputfilter.trimwhitespace.php 27 Dec 2003 23:19:50 -0000 1.3 @@ -64,8 +64,10 @@ function smarty_outputfilter_trimwhitespace_replace($search_str, $replace, & $subject) { $_len = strlen($search_str); $_pos = 0; - for ($_i=0, $_count=count($replace); $_i<$_count; $_i++) - if (($_pos=strpos($subject, $search_str, $_pos))!==false) + if (empty($replace)) return; + $_count = count($replace); + for ($_i=0; $_i<$_count; $_i++) + if (($_pos=strpos($subject, $search_str, $_pos))!==false) $subject = substr_replace($subject, $replace[$_i], $_pos, $_len); else break;

« previous php.smarty.dev (#2013) next »