diff options
author | Raymond Hettinger <python@rcn.com> | 2016-03-04 17:55:07 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2016-03-04 17:55:07 (GMT) |
commit | d79d5b1a50347b06397e160440e6bb9dd5a8ed43 (patch) | |
tree | f6461aa3bceec4fd97dffac98625be74fa0d359b /Modules | |
parent | 96c058b4de0652d52687bbc9d3bb70f4d7f669e9 (diff) | |
download | cpython-d79d5b1a50347b06397e160440e6bb9dd5a8ed43.zip cpython-d79d5b1a50347b06397e160440e6bb9dd5a8ed43.tar.gz cpython-d79d5b1a50347b06397e160440e6bb9dd5a8ed43.tar.bz2 |
More logicial order. Move space saving step to just before it is used.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_collectionsmodule.c | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c index 7dcd7e7..19a86d1 100644 --- a/Modules/_collectionsmodule.c +++ b/Modules/_collectionsmodule.c @@ -386,6 +386,13 @@ deque_extend(dequeobject *deque, PyObject *iterable) return result; } + it = PyObject_GetIter(iterable); + if (it == NULL) + return NULL; + + if (maxlen == 0) + return consume_iterator(it); + /* Space saving heuristic. Start filling from the left */ if (Py_SIZE(deque) == 0) { assert(deque->leftblock == deque->rightblock); @@ -394,13 +401,6 @@ deque_extend(dequeobject *deque, PyObject *iterable) deque->rightindex = 0; } - it = PyObject_GetIter(iterable); - if (it == NULL) - return NULL; - - if (maxlen == 0) - return consume_iterator(it); - iternext = *Py_TYPE(it)->tp_iternext; while ((item = iternext(it)) != NULL) { if (deque_append_internal(deque, item, maxlen) < 0) { @@ -433,6 +433,13 @@ deque_extendleft(dequeobject *deque, PyObject *iterable) return result; } + it = PyObject_GetIter(iterable); + if (it == NULL) + return NULL; + + if (maxlen == 0) + return consume_iterator(it); + /* Space saving heuristic. Start filling from the right */ if (Py_SIZE(deque) == 0) { assert(deque->leftblock == deque->rightblock); @@ -441,13 +448,6 @@ deque_extendleft(dequeobject *deque, PyObject *iterable) deque->rightindex = BLOCKLEN - 2; } - it = PyObject_GetIter(iterable); - if (it == NULL) - return NULL; - - if (maxlen == 0) - return consume_iterator(it); - iternext = *Py_TYPE(it)->tp_iternext; while ((item = iternext(it)) != NULL) { if (deque_appendleft_internal(deque, item, maxlen) < 0) { |