mirror of
https://github.com/python/cpython.git
synced 2025-08-03 08:34:29 +00:00
list_inplace_concat() is now expressed in terms of list_extend() which
avoids creating an intermediate tuple for iterable arguments other than lists or tuples. In other words, a+=b no longer requires extra memory when b is not a list or tuple. The list and tuple cases are unchanged.
This commit is contained in:
parent
4252a7a5d1
commit
97bc618229
1 changed files with 13 additions and 14 deletions
|
@ -707,20 +707,6 @@ listextend_internal(PyListObject *self, PyObject *b)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
list_inplace_concat(PyListObject *self, PyObject *other)
|
||||
{
|
||||
other = PySequence_Fast(other, "argument to += must be iterable");
|
||||
if (!other)
|
||||
return NULL;
|
||||
|
||||
if (listextend_internal(self, other) < 0)
|
||||
return NULL;
|
||||
|
||||
Py_INCREF(self);
|
||||
return (PyObject *)self;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
listextend(PyListObject *self, PyObject *b)
|
||||
{
|
||||
|
@ -790,6 +776,19 @@ listextend(PyListObject *self, PyObject *b)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
list_inplace_concat(PyListObject *self, PyObject *other)
|
||||
{
|
||||
PyObject *result;
|
||||
|
||||
result = listextend(self, other);
|
||||
if (result == NULL)
|
||||
return result;
|
||||
Py_DECREF(result);
|
||||
Py_INCREF(self);
|
||||
return (PyObject *)self;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
listpop(PyListObject *self, PyObject *args)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue