From: Robert Bradshaw Date: Fri, 27 Feb 2009 08:22:20 +0000 (-0800) Subject: Optimize negative indexing. X-Git-Tag: 0.11.rc~21 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=1e0af779a2e53bfb837d7c140b2ce0b9689eb534;p=cython.git Optimize negative indexing. --- diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index 085decb6..d16edfd3 100644 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@ -5418,8 +5418,8 @@ static INLINE PyObject *__Pyx_GetItemInt_%(type)s(PyObject *o, Py_ssize_t i, int Py_INCREF(r); return r; } - else if ((i == -1) & likely(Py%(type)s_GET_SIZE(o) > 0)) { - PyObject *r = Py%(type)s_GET_ITEM(o, Py%(type)s_GET_SIZE(o) - 1); + else if ((-Py%(type)s_GET_SIZE(o) <= i) & (i < 0)) { + PyObject *r = Py%(type)s_GET_ITEM(o, Py%(type)s_GET_SIZE(o) + i); Py_INCREF(r); return r; }