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

Marcus Krause marcus#exp2010 at t3sec.info
Sun Sep 5 00:43:43 CEST 2010


Hi!

Helmut Hummel schrieb am 09/04/2010 10:24 PM Uhr:
> Hi,
> 
> On 28.08.10 17:38, François Suter wrote:
>>> 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.
>> +1 after reading and testing.
> 
> +1 after reading and testing.

Here's some output from a test script with a bunch of iterations:

Before: foo_bar%
After:  foo\_bar\% (preg_replace)| Parsetime: 0.302683115005  | 100%
After:  foo\_bar\% (str_replace) | Parsetime: 0.298494100571  |  99%
After:  foo\_bar\% (addcslashes) | Parsetime: 0.0949509143829 |  31%


I guess we should use addcslashes, a specialized function for that use
case. ;-)


Marcus.


More information about the TYPO3-team-core mailing list