diff options
author | Raymond Hettinger <python@rcn.com> | 2004-03-11 07:34:19 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2004-03-11 07:34:19 (GMT) |
commit | 97bc6182297ab383d54dca4b85fe656a658e7f0d (patch) | |
tree | 92921c8f2ad33a9e1e62e609681f66c90cf04310 /Objects | |
parent | 4252a7a5d1c0bbc41abeab2ae5ce29f42cd9ace8 (diff) | |
download | cpython-97bc6182297ab383d54dca4b85fe656a658e7f0d.zip cpython-97bc6182297ab383d54dca4b85fe656a658e7f0d.tar.gz cpython-97bc6182297ab383d54dca4b85fe656a658e7f0d.tar.bz2 |
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.
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/listobject.c | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/Objects/listobject.c b/Objects/listobject.c index b61d7da..6bb6d8c7 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -708,20 +708,6 @@ listextend_internal(PyListObject *self, PyObject *b) } 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) { PyObject *it; /* iter(v) */ @@ -791,6 +777,19 @@ listextend(PyListObject *self, PyObject *b) } 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) { int i = -1; |