[issue21118] str.translate is absurdly slow in majority of use cases (takes up to 60x longer than similar functions)

Josh Rosenberg report at bugs.python.org
Tue Apr 1 23:20:24 CEST 2014


Josh Rosenberg added the comment:

@haypo: Are you planning to run with this then? Or shall I pick up where your patch leaves off?

Thanks for the pointer to the codecs charmap_build; it's not documented anywhere that I can tell, so I didn't even know it existed. Now to dig into the source to figure out what it does and how to use it (both in C and Python).

I know about the fundamental design differences that makes bytes.translate kick str.translate's butt; my plan to make a special purpose mapping-like object that didn't require C layer code to wrap up Py_UCS4 in PyLong, or pull Py_UCS4 out of PyUnicode/PyLong objects was largely to try and get a bytes.translate like implementation, but if 
codecs.charmap_build()/PyUnicode_BuildEncodingMap() can get me 90% of the way there without reinventing the wheel, it's clearly worth looking at.

Again, let me know if it's okay if I try to finish off the work you began, or if you'd prefer to do it yourself.

----------

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


More information about the Python-bugs-list mailing list