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

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


Am 04.10.11 19:50, schrieb Antoine Pitrou:
> On Tue, 04 Oct 2011 19:49:09 +0200
> "Martin v. Löwis"<martin at v.loewis.de>  wrote:
>
>>> +        result = PyUnicode_New(slicelength, PyUnicode_MAX_CHAR_VALUE(self));
>>
>> This is incorrect: the maxchar of the slice might be smaller than the
>> maxchar of the input string.
>
> I thought that heuristic would be good enough. I'll try to fix it.

No - strings must always be in the canonical form. For example,
PyUnicode_RichCompare considers string unequal if they have different
kinds. As a consequence, your slice result may not compare equal to
a canonical variant of itself.


More information about the Python-Dev mailing list