Speed-up argument parsing for common cases in deque.__init__()(GH-11717)

This commit is contained in:
Raymond Hettinger 2019-01-31 22:13:43 -08:00 committed by GitHub
parent ffdf1c30ab
commit 05f1b93f58
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 3 deletions

View 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))