[TYPO3-core] RFC #14997: Performance: t3lib_db->escapeStrForLike() is using preg_replace, which is not necessary

François Suter fsu-lists at cobweb.ch
Thu Sep 30 17:29:35 CEST 2010


REMINDER

Needs only an additional non-core review

> Hi,
>
>> Problem:
>> The function t3lib_db->escapeStrForLike() is using preg_replace to escape
>> the values '%' and '_' with a '\' for a sql-like-statement.
>> preg_replace takes a lot of recources and is not necessary for such a
>> simple replacement.
>>
>> Solution:
>> use str_replace instead.
>
> Sorry for dropping out of sight for such a long time. Here's v3 using
> addcslashes() as suggested by Markus, which is indeed far better in
> terms of performance:
>
> Before: foo\_bar\%
> After: foo\\_bar\\% (preg_replace) | Parsetime: 0.170912
> After: foo\\_bar\\% (str_replace) | Parsetime: 0.160822
> After: foo\\_bar\\% (addcslashes) | Parsetime: 0.054765
>
> (on my Mac laptop, running PHP 5.3.1)
>
> +1 on reading and testing the solution with addcslashes().
>
> Note that there's a new unit test in this patch, which ensure that the
> behavior of t3lib_db::escapeStrForLike() is covered.
>
> Cheers
>


-- 

Francois Suter
Cobweb Development Sarl - http://www.cobweb.ch


More information about the TYPO3-team-core mailing list