]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
In-line the append operations inside deque_inplace_repeat().
authorRaymond Hettinger <python@rcn.com>
Sat, 12 Sep 2015 15:00:20 +0000 (11:00 -0400)
committerRaymond Hettinger <python@rcn.com>
Sat, 12 Sep 2015 15:00:20 +0000 (11:00 -0400)
Modules/_collectionsmodule.c

index db27e923e9ec494b569b6d574233eb95e9772317..7f814607961f0a98ee89bf8c2a3e15a3f5ed3a4b 100644 (file)
@@ -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;
     }