mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
Add a spacing saving heuristic to deque's extend methods
This commit is contained in:
parent
bbf8ce5b87
commit
d9c116ca40
2 changed files with 18 additions and 2 deletions
|
@ -332,6 +332,14 @@ deque_extend(dequeobject *deque, PyObject *iterable)
|
|||
return result;
|
||||
}
|
||||
|
||||
/* Space saving heuristic. Start filling from the left */
|
||||
if (Py_SIZE(deque) == 0) {
|
||||
assert(deque->leftblock == deque->rightblock);
|
||||
assert(deque->leftindex == deque->rightindex+1);
|
||||
deque->leftindex = 1;
|
||||
deque->rightindex = 0;
|
||||
}
|
||||
|
||||
it = PyObject_GetIter(iterable);
|
||||
if (it == NULL)
|
||||
return NULL;
|
||||
|
@ -385,6 +393,14 @@ deque_extendleft(dequeobject *deque, PyObject *iterable)
|
|||
return result;
|
||||
}
|
||||
|
||||
/* Space saving heuristic. Start filling from the right */
|
||||
if (Py_SIZE(deque) == 0) {
|
||||
assert(deque->leftblock == deque->rightblock);
|
||||
assert(deque->leftindex == deque->rightindex+1);
|
||||
deque->leftindex = BLOCKLEN - 1;
|
||||
deque->rightindex = BLOCKLEN - 2;
|
||||
}
|
||||
|
||||
it = PyObject_GetIter(iterable);
|
||||
if (it == NULL)
|
||||
return NULL;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue