mirror of https://github.com/python/cpython
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.
This commit is contained in:
parent
99ee9c70a7
commit
f7a4c488b5
|
@ -461,12 +461,12 @@ static PyObject *
|
||||||
keyobject_richcompare(PyObject *ko, PyObject *other, int op)
|
keyobject_richcompare(PyObject *ko, PyObject *other, int op)
|
||||||
{
|
{
|
||||||
PyObject *res;
|
PyObject *res;
|
||||||
PyObject *args;
|
|
||||||
PyObject *x;
|
PyObject *x;
|
||||||
PyObject *y;
|
PyObject *y;
|
||||||
PyObject *compare;
|
PyObject *compare;
|
||||||
PyObject *answer;
|
PyObject *answer;
|
||||||
static PyObject *zero;
|
static PyObject *zero;
|
||||||
|
PyObject* stack[2];
|
||||||
|
|
||||||
if (zero == NULL) {
|
if (zero == NULL) {
|
||||||
zero = PyLong_FromLong(0);
|
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
|
/* Call the user's comparison function and translate the 3-way
|
||||||
* result into true or false (or error).
|
* result into true or false (or error).
|
||||||
*/
|
*/
|
||||||
args = PyTuple_New(2);
|
stack[0] = x;
|
||||||
if (args == NULL)
|
stack[1] = y;
|
||||||
return NULL;
|
res = _PyObject_FastCall(compare, stack, 2, NULL);
|
||||||
Py_INCREF(x);
|
if (res == NULL) {
|
||||||
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)
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
answer = PyObject_RichCompare(res, zero, op);
|
answer = PyObject_RichCompare(res, zero, op);
|
||||||
Py_DECREF(res);
|
Py_DECREF(res);
|
||||||
return answer;
|
return answer;
|
||||||
|
|
Loading…
Reference in New Issue