Commit 8d3a92fe authored by Robert Bradshaw's avatar Robert Bradshaw

Faster list setting when bounds check and wrapparound are disabled.

parent 60a72ceb
......@@ -3172,6 +3172,12 @@ class IndexNode(ExprNode):
def generate_setitem_code(self, value_code, code):
if self.index.type.is_int:
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(
......
......@@ -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)) ? \
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment