[prev in list] [next in list] [prev in thread] [next in thread] 

List:       phplib
Subject:    [PHPLIB] Slow templates?
From:       Stanislav Malyshev <stas () zend ! com>
Date:       2000-01-28 19:07:58
[Download RAW message or body]

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@zend.com          
+972-3-6139665

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

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic