[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
- Previous message: [Python-Dev] [Python-checkins] cpython: Migrate str.expandtabs to the new API
- Next message: [Python-Dev] [Python-checkins] cpython: Optimize string slicing to use the new API
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
+ 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
- Previous message: [Python-Dev] [Python-checkins] cpython: Migrate str.expandtabs to the new API
- Next message: [Python-Dev] [Python-checkins] cpython: Optimize string slicing to use the new API
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]