[TYPO3-core] RFC: T3-speedup preg insted of ereg

Bernhard Kraft kraftb at kraftb.at
Sun Dec 25 18:07:27 CET 2005


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Christian Jul Jensen wrote:
> On Saturday 05 November 2005 00:52, Michael Stucki wrote:
>>- Kasper checks for empty strings using strcmp, you make a "===" check
>>instead. Is there any difference between them? Which of those methods is
>>faster?
> 
> I didn't look into the code but remember that strcmp and === are not 
> equivavalent strcmp is binary safe, but does not check the type of the 
> parameters, but does on-the-fly casting.


I do NOT check for emtpy strings using "===" !

I do checks like:


$start = strpos($content, $marker);
if ($start===false) { return ''; }

- From the PHP-Manual for "strpos" :
- ----------------<cite>-------------------
 If needle is not found, strpos() will return boolean FALSE.
- ----------------</cite>-------------------

So "strpos" returns either an INT (0-n) or FALSE if the searched string wasn't found.

You can only check for "false" using === AFAIK.

Kasper didn't check for a strpos returning "false" in his previous code:
- --------------------
$start = strpos($content, $marker)+strlen($marker);
$stop = @strpos($content, $marker, $start+1);
$sub = substr($content, $start, $stop-$start);
- --------------------

So if you had NO marker at all both start and stop would be false and the result would be an empty
string (same as after my changes)

But if a start-marker was found (i.e: $start==10) but no stop marker ($stop==false) then the result
of $stop-$start = 0-10 = -10 . And this would simply result in returning everything from the start
position till -10 characters from the end - which is surely not what it was inteded to do.



Update: Michael Stucki and I asked Ernesto Baschny to make a benchmark before and after the modification
so we have some visible results we could present. Ernesto is known to know very well how to make benchmakrs -
i for myself hadn't ever the requirement for such a thing and don't know how I would have to set-up the
testing tools.

But until right now we didn't get any response from him.


I think I will apply the patch tomorrow and hope that it is before 4.0.0 sources are taken out of CVS :)


greets,
Bernhard
- --
- ----------------------------------------------------------------------
"Freiheit ist immer auch die Freiheit des Andersdenkenden"
Rosa Luxemburg, 1871 - 1919
- ----------------------------------------------------------------------
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFDrtHOIl4dkVkDMFkRAviMAJ98aF5hpHf5lmqlJy8cQsD/xL261gCfdkj8
KtKJrzGHl8Y4Squ+EOnYUcQ=
=o2Mf
-----END PGP SIGNATURE-----



More information about the TYPO3-team-core mailing list