mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
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:
parent
cb08a71c5c
commit
7934266875
2 changed files with 28 additions and 24 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue