]> granicus.if.org Git - python/commitdiff
Speed-up argument parsing for common cases in deque.__init__()(GH-11717)
authorRaymond Hettinger <rhettinger@users.noreply.github.com>
Fri, 1 Feb 2019 06:13:43 +0000 (22:13 -0800)
committerGitHub <noreply@github.com>
Fri, 1 Feb 2019 06:13:43 +0000 (22:13 -0800)
Modules/_collectionsmodule.c

index a2b683e16663b9a7e358eac6fdc08b9ab8eb2cd0..280b15d73b1ff2f61435a2adbd0644fca5c2af05 100644 (file)
@@ -1463,9 +1463,13 @@ deque_init(dequeobject *deque, PyObject *args, PyObject *kwdargs)
     Py_ssize_t maxlen = -1;
     char *kwlist[] = {"iterable", "maxlen", 0};
 
-    if (kwdargs == NULL) {
-        if (!PyArg_UnpackTuple(args, "deque()", 0, 2, &iterable, &maxlenobj))
-            return -1;
+    if (kwdargs == NULL && PyTuple_GET_SIZE(args) <= 2) {
+        if (PyTuple_GET_SIZE(args) > 0) {
+            iterable = PyTuple_GET_ITEM(args, 0);
+        }
+        if (PyTuple_GET_SIZE(args) > 1) {
+            maxlenobj = PyTuple_GET_ITEM(args, 1);
+        }
     } else {
         if (!PyArg_ParseTupleAndKeywords(args, kwdargs, "|OO:deque", kwlist,
                                          &iterable, &maxlenobj))