summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2019-01-12 06:25:41 (GMT)
committerGitHub <noreply@github.com>2019-01-12 06:25:41 (GMT)
commit793426687509be24a42663a27e568cc92dcc07f6 (patch)
tree905154eb18d4d654b3c0d295f571b96e6250c75b /Modules
parentcb08a71c5c534f33d9486677534dafb087c30e8c (diff)
downloadcpython-793426687509be24a42663a27e568cc92dcc07f6.zip
cpython-793426687509be24a42663a27e568cc92dcc07f6.tar.gz
cpython-793426687509be24a42663a27e568cc92dcc07f6.tar.bz2
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.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_operator.c21
1 files changed, 10 insertions, 11 deletions
diff --git a/Modules/_operator.c b/Modules/_operator.c
index d6c6a18..d291ec1 100644
--- a/Modules/_operator.c
+++ b/Modules/_operator.c
@@ -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;