[Python-Dev] [Python-checkins] cpython: Optimize string slicing to use the new API (original) (raw)

"Martin v. Löwis" martin at v.loewis.de
Tue Oct 4 19:49:09 CEST 2011


+ result = PyUnicodeNew(slicelength, PyUnicodeMAXCHARVALUE(self));

This is incorrect: the maxchar of the slice might be smaller than the maxchar of the input string. So you'll need to iterate over the input string first, compute the maxchar, and then allocate the result string.

Or you allocate a temporary buffer of (1<<(kind-1)) * slicelength bytes, copy the slice, allocate the target object with PyUnicode_FromKindAndData, and release the temporary buffer.

Regards, Martin



More information about the Python-Dev mailing list