Optimize negative indexing.
authorRobert Bradshaw <robertwb@math.washington.edu>
Fri, 27 Feb 2009 08:22:20 +0000 (00:22 -0800)
committerRobert Bradshaw <robertwb@math.washington.edu>
Fri, 27 Feb 2009 08:22:20 +0000 (00:22 -0800)
Cython/Compiler/ExprNodes.py

index 085decb6a99e663863d346f20baeb0e9f7df3044..d16edfd3ddc5ede3f292839eb0d47d76593ff034 100644 (file)
@@ -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;
         }