mirror of
https://github.com/python/cpython.git
synced 2025-11-02 19:12:55 +00:00
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).
This commit is contained in:
parent
c67a15d865
commit
6c87af5d87
1 changed files with 5 additions and 5 deletions
|
|
@ -2186,7 +2186,7 @@ PyObject *
|
||||||
PyList_AsTuple(PyObject *v)
|
PyList_AsTuple(PyObject *v)
|
||||||
{
|
{
|
||||||
PyObject *w;
|
PyObject *w;
|
||||||
PyObject **p;
|
PyObject **p, **q;
|
||||||
Py_ssize_t n;
|
Py_ssize_t n;
|
||||||
if (v == NULL || !PyList_Check(v)) {
|
if (v == NULL || !PyList_Check(v)) {
|
||||||
PyErr_BadInternalCall();
|
PyErr_BadInternalCall();
|
||||||
|
|
@ -2197,12 +2197,12 @@ PyList_AsTuple(PyObject *v)
|
||||||
if (w == NULL)
|
if (w == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
p = ((PyTupleObject *)w)->ob_item;
|
p = ((PyTupleObject *)w)->ob_item;
|
||||||
memcpy((void *)p,
|
q = ((PyListObject *)v)->ob_item;
|
||||||
(void *)((PyListObject *)v)->ob_item,
|
|
||||||
n*sizeof(PyObject *));
|
|
||||||
while (--n >= 0) {
|
while (--n >= 0) {
|
||||||
Py_INCREF(*p);
|
Py_INCREF(*q);
|
||||||
|
*p = *q;
|
||||||
p++;
|
p++;
|
||||||
|
q++;
|
||||||
}
|
}
|
||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue