View previous topic :: View next topic |
Author |
Message |
aloner Smarty Rookie
Joined: 24 Apr 2003 Posts: 24
|
Posted: Fri Apr 25, 2003 9:35 am Post subject: postfilter.glue_php |
|
|
There are a lot of code like "?> <?php" in compiled templates. I suppose that removing them will speed up parsing a bit.
Here's the code:
[php:1:b5aadcfdee]
<?php
/*
* Smarty plugin
* -------------------------------------------------------------
* File: postfilter.glue_php.php
* Type: postfilter
* Name: glue_php
* Purpose: Glues PHP blocks together. Should speed up parsing a little (probably).
* -------------------------------------------------------------
*/
function smarty_postfilter_glue_php($compiled, &$smarty)
{
return preg_replace('!\?\>\s*\<\?php!', "\n", $compiled);
}
?>
[/php:1:b5aadcfdee] _________________ Your ad here. |
|
Back to top |
|
andre Smarty Pro
Joined: 23 Apr 2003 Posts: 164 Location: Karlsruhe, Germany
|
Posted: Fri Apr 25, 2003 10:15 am Post subject: |
|
|
Simple but nice |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Fri Apr 25, 2003 2:45 pm Post subject: |
|
|
You wouldn't want to clean these up if there are spaces between them, you'd lose some (possibly intentional) formatting.
now, removing:
?><?php
and:
?>\n<?php
would be feasible, since this doesn't alter the template output. I'll look into this, maybe it's something Smarty should do by default.
Monte |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Fri Apr 25, 2003 5:09 pm Post subject: |
|
|
removing [php:1:dcb336d7d8]?>\n<?php[/php:1:dcb336d7d8] is only acceptable for HTML-only output. I think the core engine should leave non- smarty portions of templates completely as-is allowing filters to do the rest.
Last edited by boots on Sat May 24, 2003 6:53 am; edited 1 time in total |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Fri Apr 25, 2003 5:23 pm Post subject: |
|
|
maybe
[php:1:af9f8e61ee]return preg_replace('!\?\>\n?\<\?php!s', "", $compiled);[/php:1:af9f8e61ee]
???
it's not heavily tested, but shouldn't have any impact on the output. |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Fri Apr 25, 2003 10:01 pm Post subject: |
|
|
boots wrote: | removing [php:1:fdec785836]?>\n<?php[/php:1:fdec785836] is only acceptable for HTML-only output. I think the core engine should leave non- smarty portions of templates completely as-is allowing filters to do the rest. |
That should be acceptible because PHP eats the newlines after ?> tags anyways.
Monte |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Fri Apr 25, 2003 11:40 pm Post subject: |
|
|
Quote: | PHP eats the newlines after ?> tags anyways. |
I forgot. That also explains a behaviour I had noticed earler but couldn't figure out. |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Fri Apr 25, 2003 11:51 pm Post subject: |
|
|
HEY! I just checked and PHP DOES NOT eat the newlines between ?> .. <?
but DOES eat them inside (natch).
Point your browser to that and you get:
BUT do a view source and you get:
All the interspersed \n are preserved! |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Sat Apr 26, 2003 12:02 am Post subject: |
|
|
of course they are preserved. php is a templating system
but a newline directly after "?>" is slurped by php.
(this is what my preg-exp mactches)
do this:
Code: |
<echo "foo"; ?>
<echo "bar"; ?>
|
it leads to
foo
bar
(one newline).
it does not lead to (as one might think)
(two newlines as in the php-source) |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Sat Apr 26, 2003 12:22 am Post subject: |
|
|
That makes it clearer. Good stuff.
I haven't tested your reg-exp. If I got it right, you are optionally matching one newline. So it won't make a difference because it would never survive PHP anyway. Right. But if that is the only case that is going on, I wonder if it justifies an extra regexp in the core for each fetch as opposed to using a filter plugin (for those who want it).
I really don't think it will speed up PHP parsing while at the same time it adds a runtime cost. |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Sat Apr 26, 2003 3:11 am Post subject: |
|
|
If this was implemented it would definately be done at compile time. After the template is compiled, strip out unnecessary close/open tags right then.
Monte |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Sat Apr 26, 2003 9:01 am Post subject: |
|
|
Does the compiler insert a \n after it inserts a <?php ?> block?
If not, perhaps a \n should be ADDED between ?> <? during output to preserve \n's that get consumed but were part of the original stream. Or, perhaps a \n should be emitted after <?php ?> blocks to eliminate the need for the replacement in the output.
update:
scratch that idea. |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Sat Apr 26, 2003 3:58 pm Post subject: |
|
|
The removal of unnecessary close/open tags has been committed to CVS.
Quote: |
Does the compiler insert a \n after it inserts a <?php ?> block?
|
Smarty does everything it can to make the output match the template. The only thing I know as an exception is Smarty comments. A {* comment *} on a line by itself (or multiline) will leave an extra newline in the output (the one after the comment.)
Monte
Last edited by mohrt on Sat Apr 26, 2003 4:03 pm; edited 1 time in total |
|
Back to top |
|
Tom Sommer Administrator
Joined: 16 Apr 2003 Posts: 47 Location: Denmark
|
Posted: Sat Apr 26, 2003 3:59 pm Post subject: |
|
|
looks good |
|
Back to top |
|
Budda Smarty Regular
Joined: 19 Apr 2003 Posts: 53 Location: Lymm, Cheshire. UK
|
Posted: Sun Aug 17, 2003 5:21 pm Post subject: |
|
|
Exactly how much faster does removing these extra ?> <?php tags make Smarty? |
|
Back to top |
|
|