[Python-checkins] Speed-up argument parsing for common cases in deque.__init__()(GH-11717)
Raymond Hettinger
webhook-mailer at python.org
Fri Feb 1 01:13:48 EST 2019
https://github.com/python/cpython/commit/05f1b93f5876ac970485ae008dd9ab3e8404f934
commit: 05f1b93f5876ac970485ae008dd9ab3e8404f934
branch: master
author: Raymond Hettinger <rhettinger at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2019年01月31日T22:13:43-08:00
summary:
Speed-up argument parsing for common cases in deque.__init__()(GH-11717)
files:
M Modules/_collectionsmodule.c
diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c
index a2b683e16663..280b15d73b1f 100644
--- a/Modules/_collectionsmodule.c
+++ b/Modules/_collectionsmodule.c
@@ -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))
More information about the Python-checkins
mailing list