mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
Only update the state variable once per iteration.
This commit is contained in:
parent
1ef1c093f2
commit
0f43bb160e
1 changed files with 8 additions and 4 deletions
|
@ -269,7 +269,6 @@ PyDoc_STRVAR(popleft_doc, "Remove and return the leftmost element.");
|
||||||
static PyObject *
|
static PyObject *
|
||||||
deque_append(dequeobject *deque, PyObject *item)
|
deque_append(dequeobject *deque, PyObject *item)
|
||||||
{
|
{
|
||||||
deque->state++;
|
|
||||||
if (deque->rightindex == BLOCKLEN - 1) {
|
if (deque->rightindex == BLOCKLEN - 1) {
|
||||||
block *b = newblock(Py_SIZE(deque));
|
block *b = newblock(Py_SIZE(deque));
|
||||||
if (b == NULL)
|
if (b == NULL)
|
||||||
|
@ -288,6 +287,8 @@ deque_append(dequeobject *deque, PyObject *item)
|
||||||
if (NEEDS_TRIM(deque, deque->maxlen)) {
|
if (NEEDS_TRIM(deque, deque->maxlen)) {
|
||||||
PyObject *olditem = deque_popleft(deque, NULL);
|
PyObject *olditem = deque_popleft(deque, NULL);
|
||||||
Py_DECREF(olditem);
|
Py_DECREF(olditem);
|
||||||
|
} else {
|
||||||
|
deque->state++;
|
||||||
}
|
}
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
}
|
}
|
||||||
|
@ -297,7 +298,6 @@ PyDoc_STRVAR(append_doc, "Add an element to the right side of the deque.");
|
||||||
static PyObject *
|
static PyObject *
|
||||||
deque_appendleft(dequeobject *deque, PyObject *item)
|
deque_appendleft(dequeobject *deque, PyObject *item)
|
||||||
{
|
{
|
||||||
deque->state++;
|
|
||||||
if (deque->leftindex == 0) {
|
if (deque->leftindex == 0) {
|
||||||
block *b = newblock(Py_SIZE(deque));
|
block *b = newblock(Py_SIZE(deque));
|
||||||
if (b == NULL)
|
if (b == NULL)
|
||||||
|
@ -316,6 +316,8 @@ deque_appendleft(dequeobject *deque, PyObject *item)
|
||||||
if (NEEDS_TRIM(deque, deque->maxlen)) {
|
if (NEEDS_TRIM(deque, deque->maxlen)) {
|
||||||
PyObject *olditem = deque_pop(deque, NULL);
|
PyObject *olditem = deque_pop(deque, NULL);
|
||||||
Py_DECREF(olditem);
|
Py_DECREF(olditem);
|
||||||
|
} else {
|
||||||
|
deque->state++;
|
||||||
}
|
}
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
}
|
}
|
||||||
|
@ -387,7 +389,6 @@ deque_extend(dequeobject *deque, PyObject *iterable)
|
||||||
|
|
||||||
iternext = *Py_TYPE(it)->tp_iternext;
|
iternext = *Py_TYPE(it)->tp_iternext;
|
||||||
while ((item = iternext(it)) != NULL) {
|
while ((item = iternext(it)) != NULL) {
|
||||||
deque->state++;
|
|
||||||
if (deque->rightindex == BLOCKLEN - 1) {
|
if (deque->rightindex == BLOCKLEN - 1) {
|
||||||
block *b = newblock(Py_SIZE(deque));
|
block *b = newblock(Py_SIZE(deque));
|
||||||
if (b == NULL) {
|
if (b == NULL) {
|
||||||
|
@ -408,6 +409,8 @@ deque_extend(dequeobject *deque, PyObject *iterable)
|
||||||
if (NEEDS_TRIM(deque, maxlen)) {
|
if (NEEDS_TRIM(deque, maxlen)) {
|
||||||
PyObject *olditem = deque_popleft(deque, NULL);
|
PyObject *olditem = deque_popleft(deque, NULL);
|
||||||
Py_DECREF(olditem);
|
Py_DECREF(olditem);
|
||||||
|
} else {
|
||||||
|
deque->state++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return finalize_iterator(it);
|
return finalize_iterator(it);
|
||||||
|
@ -451,7 +454,6 @@ deque_extendleft(dequeobject *deque, PyObject *iterable)
|
||||||
|
|
||||||
iternext = *Py_TYPE(it)->tp_iternext;
|
iternext = *Py_TYPE(it)->tp_iternext;
|
||||||
while ((item = iternext(it)) != NULL) {
|
while ((item = iternext(it)) != NULL) {
|
||||||
deque->state++;
|
|
||||||
if (deque->leftindex == 0) {
|
if (deque->leftindex == 0) {
|
||||||
block *b = newblock(Py_SIZE(deque));
|
block *b = newblock(Py_SIZE(deque));
|
||||||
if (b == NULL) {
|
if (b == NULL) {
|
||||||
|
@ -472,6 +474,8 @@ deque_extendleft(dequeobject *deque, PyObject *iterable)
|
||||||
if (NEEDS_TRIM(deque, maxlen)) {
|
if (NEEDS_TRIM(deque, maxlen)) {
|
||||||
PyObject *olditem = deque_pop(deque, NULL);
|
PyObject *olditem = deque_pop(deque, NULL);
|
||||||
Py_DECREF(olditem);
|
Py_DECREF(olditem);
|
||||||
|
} else {
|
||||||
|
deque->state++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return finalize_iterator(it);
|
return finalize_iterator(it);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue