Skip to content

Commit 05f1b93

Browse files
authored
Speed-up argument parsing for common cases in deque.__init__()(GH-11717)
1 parent ffdf1c3 commit 05f1b93

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

Modules/_collectionsmodule.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1463,9 +1463,13 @@ deque_init(dequeobject *deque, PyObject *args, PyObject *kwdargs)
14631463
Py_ssize_t maxlen = -1;
14641464
char *kwlist[] = {"iterable", "maxlen", 0};
14651465

1466-
if (kwdargs == NULL) {
1467-
if (!PyArg_UnpackTuple(args, "deque()", 0, 2, &iterable, &maxlenobj))
1468-
return -1;
1466+
if (kwdargs == NULL && PyTuple_GET_SIZE(args) <= 2) {
1467+
if (PyTuple_GET_SIZE(args) > 0) {
1468+
iterable = PyTuple_GET_ITEM(args, 0);
1469+
}
1470+
if (PyTuple_GET_SIZE(args) > 1) {
1471+
maxlenobj = PyTuple_GET_ITEM(args, 1);
1472+
}
14691473
} else {
14701474
if (!PyArg_ParseTupleAndKeywords(args, kwdargs, "|OO:deque", kwlist,
14711475
&iterable, &maxlenobj))

0 commit comments

Comments
 (0)