[Cython] [cython] Initial startswith / endswith optimization (#35)

Robert Bradshaw robertwb at math.washington.edu
Thu May 26 09:40:11 CEST 2011

On Thu, May 26, 2011 at 12:27 AM, Stefan Behnel <stefan_ml at behnel.de> wrote:
> 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.

I was referring to Python-level things like startswith.

On this note, the pattern of swapping out builtin methods (and perhaps
functions) with more optimized C versions is something that perhaps it
would be good to be able to do more generally, rather than hard coding
the list into Optimize.py. We floated such "overlay" ideas way back in
the day.

- Robert

More information about the cython-devel mailing list