From 1e0af779a2e53bfb837d7c140b2ce0b9689eb534 Mon Sep 17 00:00:00 2001 From: Robert Bradshaw Date: Fri, 27 Feb 2009 00:22:20 -0800 Subject: [PATCH] Optimize negative indexing. --- Cython/Compiler/ExprNodes.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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; } -- 2.26.2