Xiang Zhang added the comment:
> The code looks too complex.
It is if looking at the patch alone. But the skill is used across stringlib and
the only thing new is the bitwise operation.
str/bytes.count is not critical but not bad if it could be optimized and
especially the effect is significa
Serhiy Storchaka added the comment:
The code looks too complex. I think that it is not worth to complicate the code
so much for optimizing just few non-critical string operations.
Many optimizations were rejected in the past due to high cost and low benefit.
--
___
Xiang Zhang added the comment:
> I understand that count() is only used when the old and new patterns of
> str.replace() have a different length.
Yes. I thought it won't help much since str.replace get many operations. But
for long string, looks good:
./python3 -m perf timeit --compare-to ~/c
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
New submission from Xiang Zhang:
I make a try to improve str.count one character for latin1 string. From
benchmark, it could enhance the speed depending on the length of the string.
# short one, a little regression
./python3 -m perf timeit --compare-to ~/cpython/python -s 's="abcdefg"'
's.coun