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

2011-10-05 Thread Martin v. Löwis
I see this as a micro-optimization. IMO we should *not* rely on these assumptions because we cannot expect that all developers of third party modules will be able to write perfect code, and some (lazy developers!) may prefer to use a fixed maximum character (e.g. 0x). Hmm. I'd like to

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

2011-10-04 Thread Martin v. Löwis
+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. So you'll need to iterate over the input string first, compute the maxchar, and then allocate the result string.

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

2011-10-04 Thread Martin v. Löwis
Am 04.10.11 19:50, schrieb Antoine Pitrou: On Tue, 04 Oct 2011 19:49:09 +0200 Martin v. Löwismar...@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

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

2011-10-04 Thread Victor Stinner
Le 04/10/2011 20:09, Martin v. Löwis a écrit : Am 04.10.11 19:50, schrieb Antoine Pitrou: On Tue, 04 Oct 2011 19:49:09 +0200 Martin v. Löwismar...@v.loewis.de wrote: + result = PyUnicode_New(slicelength, PyUnicode_MAX_CHAR_VALUE(self)); This is incorrect: the maxchar of the slice might be