Commit 098b84f6 authored by Robert Bradshaw's avatar Robert Bradshaw

Merge pull request #105 from scoder/_list_append_opt

more optimistic PyList_Append() implementation
parents dd8ac390 a6afe0e5
......@@ -5443,7 +5443,8 @@ class ComprehensionAppendNode(Node):
def generate_execution_code(self, code):
if self.target.type is list_type:
function = "PyList_Append"
code.globalstate.use_utility_code(UtilityCode.load_cached("InternalListAppend", "Optimize.c"))
function = "__Pyx_PyList_Append"
elif self.target.type is set_type:
function = "PySet_Add"
else:
......
......@@ -2,11 +2,10 @@
static CYTHON_INLINE PyObject* __Pyx_PyObject_Append(PyObject* L, PyObject* x) {
if (likely(PyList_CheckExact(L))) {
if (PyList_Append(L, x) < 0) return NULL;
if (unlikely(PyList_Append(L, x) < 0)) return NULL;
Py_INCREF(Py_None);
return Py_None; /* this is just to have an accurate signature */
}
else {
} else {
PyObject *r, *m;
m = __Pyx_GetAttrString(L, "append");
if (!m) return NULL;
......@@ -16,6 +15,23 @@ static CYTHON_INLINE PyObject* __Pyx_PyObject_Append(PyObject* L, PyObject* x) {
}
}
/////////////// InternalListAppend.proto ///////////////
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE int __Pyx_PyList_Append(PyObject* list, PyObject* x) {
PyListObject* L = (PyListObject*) list;
Py_ssize_t len = Py_SIZE(list);
if (likely(L->allocated > len)) {
Py_INCREF(x);
PyList_SET_ITEM(list, len, x);
Py_SIZE(list) = len+1;
return 0;
}
return PyList_Append(list, x);
}
#else
#define __Pyx_PyList_Append(L,x) PyList_Append(L,x)
#endif
/////////////// pop.proto ///////////////
......
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