Re: [SMARTY] new plugin: mailto
| From: | Monte Ohrt | Date: | Wed, 22 May 2002 05:47:04 +0000 |
| Subject: | Re: [SMARTY] new plugin: mailto | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-4350@lists.php.net to get a copy of this message | ||
I sent an e-mail to Nick Lindridge (php-accelerator author), asking if phpa optimizes this (or anything like it) at the compilation cycle, or if it is even possible. Wouldn't that be nice to have little optimizations like this automated ;-)
In any event, that is something I'll put on the high priority list for Smarty.
Monte
Alan McFarlane wrote:
Hehe, I'm surprised no one has spotted this trick. I've been using it for a long time now in my C and C++ code with excellent results. Likewise, I agreee that a problem ~may~ arise if the array size changes during execution, however I can't say I've ever suffered from that particular problem. I'll look forward to the new code - (hmm, I wonder if PHP source uses this trick, or Apache?) -- Alan McFarlane -----Original Message----- From: Monte Ohrt [mailto:monte@ispi.net] Sent: 22 May 2002 02:55 To: Alan McFarlane Cc: Kelly Cochran; Smarty General Subject: Re: [SMARTY] new plugin: mailto This works, and after doing some simple tests the results are almost exactly 50% faster no matter how big the array is. Seeing this kind of improvement, I took a quick look at the Smarty code base. Almost every for loop recounts on each iteration. It looks like there is room for noticable improvement with a simple change to each loop (?) This would definately be a good idea for the compiled templates. The exception to the rule is if the variable being counted is altered during the loop. This is probably rare in the Smarty code, but must be examined for. Monte Alan McFarlane wrote:or (untested) for ($i = 0, $j = count($mail_params); $i < $j; $i++) { //... } -- Alan McFarlane amcfarlane@bigfoot.com -----Original Message----- From: Kelly Cochran [mailto:kcochran@trolans.net] Sent: 22 May 2002 00:04 To: Smarty General Subject: Re: [SMARTY] new plugin: mailto Why not something like: if(count($mail_parms)) { $address .= '?' . implode('&', $mail_parms); } Then there's now the only one call to count() as well as ditching the now extraneous incrementer. Steve wrote:-- Smarty General Mailing List (http://smarty.php.net/) To unsubscribe, visit: http://www.php.net/unsub.phpJust a minor performance note here: in this code snippet for ($i=0; $i<count($mail_parms); $i++) { $mail_parm_vals .= (0==$i) ? '?' : '&'; $mail_parm_vals .= $mail_parms[$i]; } count() is called once for each loop iteration. Obviously in thiscontextthat is only a couple of times. But in larger loops, this can become expensive. Another way to do it would be to call count once, assign the value and put the value in the for loop expression.-- - Kelly Cochran - (KC543) e-mail: kcochran@trolans.net WWW: http://www.trolans.net/