Re: [SMARTY-DEV] Suggestion for the outputfilter.trimwhitespace.php plugin

From: Date: Fri, 02 Jan 2004 10:08:59 +0000
Subject: Re: [SMARTY-DEV] Suggestion for the outputfilter.trimwhitespace.php plugin
References: 1  Groups: php.smarty.dev 
Request: Send a blank email to php-smarty-dev+get-2014@lists.php.net to get a copy of this message
On Thu, Jan 01, 2004 at 11:39:08PM -0500, Gerard Samuel wrote: > 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. the count()-call is in the initialization of the for-loop: for ($_i=0, $_count=count($replace); $_i<$_count; $_i++) (note: it's a comma after "$_i=0" - not a semicolon) so count() is only called once right now. > 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; > > -- > Smarty Development Mailing List (http://smarty.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php

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