On Feb 27, 2009, at 12:18 AM, Stefan Behnel wrote:

> Robert Bradshaw wrote:
>> On Feb 26, 2009, at 11:41 PM, Stefan Behnel wrote:
>>> I'd like to also optimise negative indices (at least -1 is extremely
>>> common),
>>> that'll definitely make the List/Tuple functions too long for  
>>> their minor
>>> differences.
>>
>> Good idea, doing that right now.
>
> What about this? I checked the assembly, and it looks not too  
> bloated to me.
>
> Stefan
>
>
> static INLINE PyObject *__Pyx_GetItemInt_%(type)s(PyObject *o,  
> Py_ssize_t
> i, int is_unsigned) {
>     if (likely(o != Py_None)) {
>         if (likely((i < Py%(type)s_GET_SIZE(o)) &
>                                  (i >= -Py%(type)s_GET_SIZE(o)))) {
>             if (unlikely(i < 0))
>                 i = Py%(type)s_GET_SIZE(o) + i;
>             PyObject *r = Py%(type)s_GET_ITEM(o, i);
>             Py_INCREF(r);
>             return r;
>         }
>     }
>     return __Pyx_GetItemInt_Generic(o, i, is_unsigned);
> }

This doesn't handle i < -len(o). I actually already implemented this,  
pushing now.

- Robert

_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to