More logicial order. Move space saving step to just before it is used.
This commit is contained in:
parent
96c058b4de
commit
d79d5b1a50
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue