[TYPO3-core] RFC: T3-speedup preg insted of ereg
Martin Kutschker
Martin.Kutschker at blackbox.net
Sat Nov 5 11:09:54 CET 2005
Michael Stucki <michael at typo3.org> writes on
Sat, 05 Nov 2005 00:52:05 +0100 (MET):
>
> - Kasper checks for empty strings using strcmp, you make a "==="
> check instead. Is there any difference between them? Which of those
> methods is faster?
Theoretically === should be faster because it has no function call.
> - Sometimes, you write complicated expressions like this one:
>
> if (preg_match('/^([^\<\>]*\-\-\>)?(.*?)(\<\!\-\-[^\<\>]*)?$/s',
> $content,
> $matches)===1) {
Why ist practically every character escaped? There is NO need to escape any character (except ]) in a character class ( eg [abc>]). Outside of character classes only regexp meta chars like . and * must be escaped.
This the above regexp can be safely written like this:
preg_match('/^([^<>]*-->)?(.*?)(<!--[^<>]*)?$/s', ...);
Hint: if you need brackets for grouping but don't need the match you can write (?:expr). expr will match but won't appear in the match array. This is also a bit faster.
eg.
preg_match('/^(?:[^<>]*-->)?(.*?)(?:<!--[^<>]*)?$/s', ..., $matches);
In $matches[1] you will find the content of the 2nd bracket.
> > Branches:
> > HEAD, 3.7(?), 3.8(?)
>
> I guess this change is much too big for maintenance releases. So it is
> for HEAD only, right?
>
> Regards, and thumbs up!
+1 for HEAD
Masi
More information about the TYPO3-team-core
mailing list