[PHPLIB] Slow templates? From: Stanislav Malyshev (stas <email protected>)
Date: 01/28/00

I've looked at the current template implementation and found that it
replaces variables with array version of preg_replace. Won't it be much
faster to do something like this:

preg_match_all("|([^{]*){([^}]+)}([^{]*)|Ams",$text,$matches,PREG_SET_ORDER);
foreach($matches as $mt) {
  print $mt[1];
  print get_var($mt[2]);
  print $mt[3];
}

I'm not sure this exactly code is bug-free, but it does the this one-path
(two, to be more precise, but I'm sure it can be made one-path too),
while current version, as I see, does one pass for every variable.

Another option would be using eval feature of the regexp with
preg_replace, with the same algorithm as above.

-- 
Stanislav Malyshev   stas <email protected>          
+972-3-6139665

- PHP3 Base Library Mailing List. Send messages to <phplib <email protected>>. To unsubscribe, send "unsubscribe" to <phplib-request <email protected>> in the body, not the subject, of your message.