summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2016-09-11 22:45:53 -0700
committerRaymond Hettinger <python@rcn.com>2016-09-11 22:45:53 -0700
commit88057171f057dad4d855155c975d3e7c85cd23e3 (patch)
tree6a993a2b7bc3731df0315ee5505bd7c4b89c751c
parent4103e4dfbce8b6d9579565ab64868a721b01d2a1 (diff)
downloadcpython-git-88057171f057dad4d855155c975d3e7c85cd23e3.tar.gz
Revert part of 3471a3515827 that caused a performance regression
-rw-r--r--Modules/_collectionsmodule.c52
1 files changed, 44 insertions, 8 deletions
diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c
index 1675102681..9ed6f14bec 100644
--- a/Modules/_collectionsmodule.c
+++ b/Modules/_collectionsmodule.c
@@ -403,10 +403,28 @@ deque_extend(dequeobject *deque, PyObject *iterable)
iternext = *Py_TYPE(it)->tp_iternext;
while ((item = iternext(it)) != NULL) {
- if (deque_append_internal(deque, item, maxlen) < 0) {
- Py_DECREF(item);
- Py_DECREF(it);
- return NULL;
+ if (deque->rightindex == BLOCKLEN - 1) {
+ block *b = newblock();
+ if (b == NULL) {
+ Py_DECREF(item);
+ Py_DECREF(it);
+ return NULL;
+ }
+ b->leftlink = deque->rightblock;
+ CHECK_END(deque->rightblock->rightlink);
+ deque->rightblock->rightlink = b;
+ deque->rightblock = b;
+ MARK_END(b->rightlink);
+ deque->rightindex = -1;
+ }
+ Py_SIZE(deque)++;
+ deque->rightindex++;
+ deque->rightblock->data[deque->rightindex] = item;
+ if (NEEDS_TRIM(deque, maxlen)) {
+ PyObject *olditem = deque_popleft(deque, NULL);
+ Py_DECREF(olditem);
+ } else {
+ deque->state++;
}
}
return finalize_iterator(it);
@@ -450,10 +468,28 @@ deque_extendleft(dequeobject *deque, PyObject *iterable)
iternext = *Py_TYPE(it)->tp_iternext;
while ((item = iternext(it)) != NULL) {
- if (deque_appendleft_internal(deque, item, maxlen) < 0) {
- Py_DECREF(item);
- Py_DECREF(it);
- return NULL;
+ if (deque->leftindex == 0) {
+ block *b = newblock();
+ if (b == NULL) {
+ Py_DECREF(item);
+ Py_DECREF(it);
+ return NULL;
+ }
+ b->rightlink = deque->leftblock;
+ CHECK_END(deque->leftblock->leftlink);
+ deque->leftblock->leftlink = b;
+ deque->leftblock = b;
+ MARK_END(b->leftlink);
+ deque->leftindex = BLOCKLEN;
+ }
+ Py_SIZE(deque)++;
+ deque->leftindex--;
+ deque->leftblock->data[deque->leftindex] = item;
+ if (NEEDS_TRIM(deque, maxlen)) {
+ PyObject *olditem = deque_pop(deque, NULL);
+ Py_DECREF(olditem);
+ } else {
+ deque->state++;
}
}
return finalize_iterator(it);