[issue28921] Make str.count one character for latin1 string faster

STINNER Victor report at bugs.python.org
Fri Dec 9 09:53:28 EST 2016


STINNER Victor added the comment:

Hum, Serhiy is better than me to review such hardcore C code :-) I let him review the patch ;-)

> short one, a little regression

In stringlib, the usual solution is to use a threshold: use a dummy loop for less than N bytes, otherwise use the ultra-optimized loop. Serhiy event implemented a "dynamic" threshold in some functions, when too many false positive are found. I don't recall where.

"And since str.replace may also go through the code path involving count, it's somewhat affected: (...) 1.07x faster"

I'm not really excited by optimizing str.count, since I don't think that this function is commonly used. But if str.replace is made faster, I'm interested :-)

I understand that count() is only used when the old and new patterns of str.replace() have a different length.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue28921>
_______________________________________


More information about the Python-bugs-list mailing list