diff options
author | Raymond Hettinger <python@rcn.com> | 2007-12-15 00:07:25 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2007-12-15 00:07:25 (GMT) |
commit | 6c87af5d876dca978199240c258eaaaf2d0040e9 (patch) | |
tree | ecaabed843f651f11db7c22bf5001de8384801b6 /Objects | |
parent | c67a15d86552245f1a55b58e319ffda345196854 (diff) | |
download | cpython-6c87af5d876dca978199240c258eaaaf2d0040e9.zip cpython-6c87af5d876dca978199240c258eaaaf2d0040e9.tar.gz cpython-6c87af5d876dca978199240c258eaaaf2d0040e9.tar.bz2 |
Optimize PyList_AsTuple(). Improve cache performance by doing the
pointer copy and object increment in one pass. For small lists,
save the overhead of the call to memcpy() -- this comes up in
calls like f(*listcomp).
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/listobject.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/Objects/listobject.c b/Objects/listobject.c index ca767da..3fa256e 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -2186,7 +2186,7 @@ PyObject * PyList_AsTuple(PyObject *v) { PyObject *w; - PyObject **p; + PyObject **p, **q; Py_ssize_t n; if (v == NULL || !PyList_Check(v)) { PyErr_BadInternalCall(); @@ -2197,12 +2197,12 @@ PyList_AsTuple(PyObject *v) if (w == NULL) return NULL; p = ((PyTupleObject *)w)->ob_item; - memcpy((void *)p, - (void *)((PyListObject *)v)->ob_item, - n*sizeof(PyObject *)); + q = ((PyListObject *)v)->ob_item; while (--n >= 0) { - Py_INCREF(*p); + Py_INCREF(*q); + *p = *q; p++; + q++; } return w; } |