summaryrefslogtreecommitdiffstats
path: root/Modules/_collectionsmodule.c
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2015-09-12 15:00:20 (GMT)
committerRaymond Hettinger <python@rcn.com>2015-09-12 15:00:20 (GMT)
commit67c78b5421ce9ebba1399e5935879ca01d5ac091 (patch)
tree1a72c9546ba90509e14d3f7ef9a7d1d5c21f3884 /Modules/_collectionsmodule.c
parent233cdb3e9c3d55a90763e9d5791b9e36f0a17882 (diff)
downloadcpython-67c78b5421ce9ebba1399e5935879ca01d5ac091.zip
cpython-67c78b5421ce9ebba1399e5935879ca01d5ac091.tar.gz
cpython-67c78b5421ce9ebba1399e5935879ca01d5ac091.tar.bz2
In-line the append operations inside deque_inplace_repeat().
Diffstat (limited to 'Modules/_collectionsmodule.c')
-rw-r--r--Modules/_collectionsmodule.c22
1 files changed, 18 insertions, 4 deletions
diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c
index db27e92..7f81460 100644
--- a/Modules/_collectionsmodule.c
+++ b/Modules/_collectionsmodule.c
@@ -567,12 +567,26 @@ deque_inplace_repeat(dequeobject *deque, Py_ssize_t n)
if (n > MAX_DEQUE_LEN)
return PyErr_NoMemory();
+ deque->state++;
for (i = 0 ; i < n-1 ; i++) {
- rv = deque_append(deque, item);
- if (rv == NULL)
- return NULL;
- Py_DECREF(rv);
+ if (deque->rightindex == BLOCKLEN - 1) {
+ block *b = newblock(Py_SIZE(deque) + i);
+ if (b == NULL) {
+ Py_SIZE(deque) += i;
+ 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;
+ }
+ deque->rightindex++;
+ Py_INCREF(item);
+ deque->rightblock->data[deque->rightindex] = item;
}
+ Py_SIZE(deque) += i;
Py_INCREF(deque);
return (PyObject *)deque;
}