bpo-35582: Inline arguments tuple unpacking in handwritten code. (GH-11524)

Inline PyArg_UnpackTuple() and _PyArg_UnpackStack() in performance
sensitive code in the builtins and operator modules.
This commit is contained in:
Serhiy Storchaka 2019-01-12 08:25:41 +02:00 committed by GitHub
parent cb08a71c5c
commit 7934266875
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 24 deletions

View file

@ -1011,15 +1011,12 @@ itemgetter_call(itemgetterobject *ig, PyObject *args, PyObject *kw)
Py_ssize_t i, nitems=ig->nitems;
assert(PyTuple_CheckExact(args));
if (kw == NULL && PyTuple_GET_SIZE(args) == 1) {
obj = PyTuple_GET_ITEM(args, 0);
}
else {
if (!_PyArg_NoKeywords("itemgetter", kw))
return NULL;
if (!PyArg_UnpackTuple(args, "itemgetter", 1, 1, &obj))
return NULL;
}
if (!_PyArg_NoKeywords("itemgetter", kw))
return NULL;
if (!_PyArg_CheckPositional("itemgetter", PyTuple_GET_SIZE(args), 1, 1))
return NULL;
obj = PyTuple_GET_ITEM(args, 0);
if (nitems == 1) {
if (ig->index >= 0
&& PyTuple_CheckExact(obj)
@ -1317,8 +1314,9 @@ attrgetter_call(attrgetterobject *ag, PyObject *args, PyObject *kw)
if (!_PyArg_NoKeywords("attrgetter", kw))
return NULL;
if (!PyArg_UnpackTuple(args, "attrgetter", 1, 1, &obj))
if (!_PyArg_CheckPositional("attrgetter", PyTuple_GET_SIZE(args), 1, 1))
return NULL;
obj = PyTuple_GET_ITEM(args, 0);
if (ag->nattrs == 1) /* ag->attr is always a tuple */
return dotted_getattr(obj, PyTuple_GET_ITEM(ag->attr, 0));
@ -1561,8 +1559,9 @@ methodcaller_call(methodcallerobject *mc, PyObject *args, PyObject *kw)
if (!_PyArg_NoKeywords("methodcaller", kw))
return NULL;
if (!PyArg_UnpackTuple(args, "methodcaller", 1, 1, &obj))
if (!_PyArg_CheckPositional("methodcaller", PyTuple_GET_SIZE(args), 1, 1))
return NULL;
obj = PyTuple_GET_ITEM(args, 0);
method = PyObject_GetAttr(obj, mc->name);
if (method == NULL)
return NULL;