diff options
author | Raymond Hettinger <python@rcn.com> | 2015-09-19 06:21:33 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2015-09-19 06:21:33 (GMT) |
commit | 0e14e6610b3cf692377996fad569496191a3f731 (patch) | |
tree | 09d396068d08c2d079fdc430f1a0046108bbc7d6 /Modules | |
parent | 6631b550d68789bce9fe2536e501539d7b649042 (diff) | |
download | cpython-0e14e6610b3cf692377996fad569496191a3f731.zip cpython-0e14e6610b3cf692377996fad569496191a3f731.tar.gz cpython-0e14e6610b3cf692377996fad569496191a3f731.tar.bz2 |
Hoist constant expression out of an inner loop
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_collectionsmodule.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c index 087f8e5..dbe44e1 100644 --- a/Modules/_collectionsmodule.c +++ b/Modules/_collectionsmodule.c @@ -371,6 +371,7 @@ static PyObject * deque_extend(dequeobject *deque, PyObject *iterable) { PyObject *it, *item; + int trim = (deque->maxlen != -1); /* Handle case where id(deque) == id(iterable) */ if ((PyObject *)deque == iterable) { @@ -417,7 +418,8 @@ deque_extend(dequeobject *deque, PyObject *iterable) Py_SIZE(deque)++; deque->rightindex++; deque->rightblock->data[deque->rightindex] = item; - deque_trim_left(deque); + if (trim) + deque_trim_left(deque); } if (PyErr_Occurred()) { Py_DECREF(it); @@ -434,6 +436,7 @@ static PyObject * deque_extendleft(dequeobject *deque, PyObject *iterable) { PyObject *it, *item; + int trim = (deque->maxlen != -1); /* Handle case where id(deque) == id(iterable) */ if ((PyObject *)deque == iterable) { @@ -480,7 +483,8 @@ deque_extendleft(dequeobject *deque, PyObject *iterable) Py_SIZE(deque)++; deque->leftindex--; deque->leftblock->data[deque->leftindex] = item; - deque_trim_right(deque); + if (trim) + deque_trim_right(deque); } if (PyErr_Occurred()) { Py_DECREF(it); |