diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index 73bbd8441edc1f46e64fcd405bab903c1e4ef588..3ad7414fdd650e7057418587cf4e8487bf9fdcc2 100755 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@ -3172,7 +3172,13 @@ class IndexNode(ExprNode): def generate_setitem_code(self, value_code, code): if self.index.type.is_int: - function = "__Pyx_SetItemInt" + if (self.base.type.is_builtin_type + and self.base.type.name == "list" + and not code.globalstate.directives['wraparound'] + and not code.globalstate.directives['boundscheck']): + function = "__Pyx_SetItemListInt_NoCheck" + else: + function = "__Pyx_SetItemInt" index_code = self.index.result() code.globalstate.use_utility_code( UtilityCode.load_cached("SetItemInt", "ObjectHandling.c")) diff --git a/Cython/Utility/ObjectHandling.c b/Cython/Utility/ObjectHandling.c index 7a78e51dfd2e618e0eccb7add1f39f0da1cabc5e..526d367dfe204d03d5874185b4811d2d45c1cbc7 100644 --- a/Cython/Utility/ObjectHandling.c +++ b/Cython/Utility/ObjectHandling.c @@ -354,6 +354,19 @@ static CYTHON_INLINE int __Pyx_SetItemInt_Fast(PyObject *o, Py_ssize_t i, PyObje return __Pyx_SetItemInt_Generic(o, PyInt_FromSsize_t(i), v); } + +#define __Pyx_SetItemListInt_NoCheck(o, i, v, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \ + __Pyx_SetItemIntList_NoCheck(o, i, v) : \ + __Pyx_SetItemInt_Generic(o, to_py_func(i), v)) + +static CYTHON_INLINE int __Pyx_SetItemIntList_NoCheck(PyObject *o, Py_ssize_t n, PyObject *v) { + PyObject* old = PyList_GET_ITEM(o, n); + Py_INCREF(v); + PyList_SET_ITEM(o, n, v); + Py_DECREF(old); + return 1; +} + /////////////// DelItemInt.proto /////////////// #define __Pyx_DelItemInt(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \ diff --git a/docs/src/tutorial/queue_example/queue.pyx b/docs/src/tutorial/queue_example/queue.pyx index b7801cd7768286eb115c50243be7d11bf2ab8810..32b3fef367103ee5f3d3909fd1b376256b454b7c 100644 --- a/docs/src/tutorial/queue_example/queue.pyx +++ b/docs/src/tutorial/queue_example/queue.pyx @@ -1,5 +1,4 @@ cimport cqueue -cimport python_exc cdef class Queue: