diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2016-08-19 16:52:35 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2016-08-19 16:52:35 (GMT) |
commit | f7a4c488b55e5f7ce9bdb85d050179ba91008b70 (patch) | |
tree | 7e629e009460ab96641cb852eb14e58a5343c1f4 /Modules | |
parent | 99ee9c70a73ec2f3db68785821a9f2867c3f637f (diff) | |
download | cpython-f7a4c488b55e5f7ce9bdb85d050179ba91008b70.zip cpython-f7a4c488b55e5f7ce9bdb85d050179ba91008b70.tar.gz cpython-f7a4c488b55e5f7ce9bdb85d050179ba91008b70.tar.bz2 |
keyobject_richcompare() now uses fast call
Issue #27128: keyobject_richcompare() now calls _PyObject_FastCall() using a
small stack allocated on the C stack to avoid a temporary tuple.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_functoolsmodule.c | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/Modules/_functoolsmodule.c b/Modules/_functoolsmodule.c index d785c49..f7dbf15 100644 --- a/Modules/_functoolsmodule.c +++ b/Modules/_functoolsmodule.c @@ -461,12 +461,12 @@ static PyObject * keyobject_richcompare(PyObject *ko, PyObject *other, int op) { PyObject *res; - PyObject *args; PyObject *x; PyObject *y; PyObject *compare; PyObject *answer; static PyObject *zero; + PyObject* stack[2]; if (zero == NULL) { zero = PyLong_FromLong(0); @@ -490,17 +490,13 @@ keyobject_richcompare(PyObject *ko, PyObject *other, int op) /* Call the user's comparison function and translate the 3-way * result into true or false (or error). */ - args = PyTuple_New(2); - if (args == NULL) - return NULL; - Py_INCREF(x); - Py_INCREF(y); - PyTuple_SET_ITEM(args, 0, x); - PyTuple_SET_ITEM(args, 1, y); - res = PyObject_Call(compare, args, NULL); - Py_DECREF(args); - if (res == NULL) + stack[0] = x; + stack[1] = y; + res = _PyObject_FastCall(compare, stack, 2, NULL); + if (res == NULL) { return NULL; + } + answer = PyObject_RichCompare(res, zero, op); Py_DECREF(res); return answer; |