[Cython] [cython] Initial startswith / endswith optimization (#35)
Stefan Behnel
stefan_ml at behnel.de
Thu May 26 09:27:49 CEST 2011
Robert Bradshaw, 25.05.2011 22:52:
> On Wed, May 25, 2011 at 1:41 PM, John Ehresman wrote:
>> On 5/25/11 3:51 PM, Robert Bradshaw wrote:
>>>
>>> I'm glad you're thinking about this question, some explanation of the
>>> various string types is at
>>> http://wiki.cython.org/enhancements/stringliterals
>>>
>>> Probably the way to do this is have one optimization for bytes, one
>>> for unicode, and then have a third type for str that dispatches to the
>>> one or the other depending on the python version (using #define).
>>
>> I think this means that the current unicode optimizations aren't used when
>> variables are declared as str and a python 3 runtime is used. Should all
>> unicode optimizations support str eventually?
>
> Yes.
Well, minus those that are not portable. For example, the return type of
indexing and iteration is the C type "Py_UCS4" for unicode, but the Python
type "str" (i.e. bytes/unicode) for "str". I also didn't take a thorough
look through the C-API functions for the str type in Py2 and Py3. Things
certainly become more ugly when trying to optimise Python code into C for
both platforms, than when leaving things at the Python type level.
Stefan
More information about the cython-devel
mailing list