summaryrefslogtreecommitdiffstats
path: root/Modules/_collectionsmodule.c
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2013-07-09 07:13:21 (GMT)
committerRaymond Hettinger <python@rcn.com>2013-07-09 07:13:21 (GMT)
commitd9c116ca403a6fa15d1af414dabc726e862714e7 (patch)
tree0bb350c8b17c6bdb5f6b8fd36c280b326e62f68d /Modules/_collectionsmodule.c
parentbbf8ce5b87f355796ec9fea1cf0adba9de5e5ce1 (diff)
downloadcpython-d9c116ca403a6fa15d1af414dabc726e862714e7.zip
cpython-d9c116ca403a6fa15d1af414dabc726e862714e7.tar.gz
cpython-d9c116ca403a6fa15d1af414dabc726e862714e7.tar.bz2
Add a spacing saving heuristic to deque's extend methods
Diffstat (limited to 'Modules/_collectionsmodule.c')
-rw-r--r--Modules/_collectionsmodule.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c
index 9924b63..67ff55b 100644
--- a/Modules/_collectionsmodule.c
+++ b/Modules/_collectionsmodule.c
@@ -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;