I noticed a similar problem sometime ago and worked out a different
solution. Let me know how this compares with yours...
It dramatically speeds the processing time because it stops all nested
escapes--by first unescaping all previously escaped text in a string and
then escaping the entire string. It also simplifies the code.
I'm not familiar with the static declaration or fully understand it's
benefits.
function BOLTescape($x, $reverse=true, $spaced=false) {
## USED IN VARIOUS PLACES TO PRESERVE OUTPUT AND BLOCK ANY FURTHER MARKUP
PROCESSING. SET REVERSE TO FALSE TO UNESCAPE A STRING OF TEXT.
if ($x == '') return;
global $Token;
$x = preg_replace('/~~([0-9]+)\*?~~/e', '$Token[$1]', $x);
if ($reverse == false) return $x;
$c = count($Token) + 1;
$Token[$c] = $x;
if ($spaced) return "~~$c*~~";
return "~~$c~~";
}
Cheers,
Dan
On Tue, Sep 20, 2011 at 8:14 PM, DrunkenMonk <[email protected]> wrote:
> I was using 3.4.15, I only changed declarations:
> static $Token = array();
> static $c = 0;
> and the usage of $c:
> $Token[++$c] = $x;
>
> On my live server I patched in the following version (using global
> instead of static variables for a tiny speed difference):
>
> function BOLTescape($x, $reverse=true, $spaced=false) {
> ## USED IN VARIOUS PLACES TO PRESERVE SOME OUTPUT AND BLOCK ANY
> FURTHER MARKUP PROCESSING. SET REVERSE TO FALSE TO UNESCAPE A STRING
> OF TEXT.
> global $Token, $TokenCount;
> //static $Token = array();
> //static $c = 0;
> if ($x == '') return;
> // if ($x == "\n") return '<>';
> if($reverse == false) {
> while (preg_match('/~~([0-9]+)\*?~~/', $x) != 0) {
> $x = preg_replace('/~~([0-9]+)\*?~~/e', '$Token[$1]', $x);
> }
> return $x;
> }
> $Token[++$TokenCount] = $x;
> if ($spaced) return "~~$TokenCount*~~";
> return "~~$TokenCount~~";
> }
>
> On Sep 21, 1:14 am, Kevin <[email protected]> wrote:
> > your new function has
> >
> > function BOLTescape($x, $reverse=true, $spaced=false) {
> >
> > with $spaced=false at the end.
> >
> > My existing one has:
> >
> > function xBOLTescape($x, $reverse=true) {
> >
> > Did you make other changes that inserted that.
> >
> > I am using 3.4.14
> >
> >
> >
> >
> >
> >
> >
> > On Tue, Sep 20, 2011 at 2:49 PM, DrunkenMonk <[email protected]> wrote:
> > > I have certain pages on my site that take a long time to load, in the
> > > order of 10 seconds.
> > > Changing BOLTescape to the following code reduced that by roughly a
> > > third:
> >
> > > function BOLTescape($x, $reverse=true, $spaced=false) {
> > > ## USED IN VARIOUS PLACES TO PRESERVE SOME OUTPUT AND BLOCK ANY
> > > FURTHER MARKUP PROCESSING. SET REVERSE TO FALSE TO UNESCAPE A STRING
> > > OF TEXT.
> > > static $Token = array();
> > > static $c = 0;
> > > if ($x == '') return;
> > > // if ($x == "\n") return '<>';
> > > if($reverse == false) {
> > > while (preg_match('/~~([0-9]+)\*?~~/', $x) != 0) $x =
> > > preg_replace('/~~([0-9]+)\*?~~/e', '$Token[$1]', $x);
> > > return $x;
> > > }
> > > $Token[++$c] = $x;
> > > if ($spaced) return "~~$c*~~";
> > > return "~~$c~~";
> > > }
> >
> > > $Token is defined as a global variable in other places but never used
> > > as far as I can see.
> > > It is, however, the count($Token) line that causes the majority of the
> > > slowdown, so $Token can remain global if this is preferred.
> >
> > > Background:
> > > On a page that took 7 seconds to load, I added a BOLTstopwatch line to
> > > the BOLTdoMarkupTable function, and found that over 3 seconds was
> > > being spent on the pre - escape markup rule. Using my suggestion, this
> > > was reduced to 0.12 seconds.
> >
> > > I'm going to go find the remaining 2 seconds of loading time and
> > > optimize them away too.
> >
> > > --
> > > You received this message because you are subscribed to the Google
> Groups
> > > "BoltWire" group.
> > > To post to this group, send email to [email protected].
> > > To unsubscribe from this group, send email to
> > > [email protected].
> > > For more options, visit this group at
> > >http://groups.google.com/group/boltwire?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups
> "BoltWire" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/boltwire?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups
"BoltWire" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/boltwire?hl=en.