Commit 459a5195 authored by Stefan Behnel's avatar Stefan Behnel

Optimise internal fallback method calls in Py3.7+ by directly unpacking the method calls.

Closes #2850.
parent c2f4cced
...@@ -1807,6 +1807,14 @@ static PyObject* __Pyx_PyObject_CallMethod0(PyObject* obj, PyObject* method_name ...@@ -1807,6 +1807,14 @@ static PyObject* __Pyx_PyObject_CallMethod0(PyObject* obj, PyObject* method_name
PyObject *method = NULL, *result = NULL; PyObject *method = NULL, *result = NULL;
int is_method = __Pyx_PyObject_GetMethod(obj, method_name, &method); int is_method = __Pyx_PyObject_GetMethod(obj, method_name, &method);
if (likely(is_method)) { if (likely(is_method)) {
#if PY_VERSION_HEX >= 0x030700A0 && CYTHON_UNPACK_METHODS && CYTHON_FAST_PYCCALL
if (Py_TYPE(method) == &PyMethodDescr_Type) {
PyMethodDescrObject *descr = (PyMethodDescrObject *)method;
result = _PyMethodDef_RawFastCallKeywords(descr->d_method, obj, NULL, 0, NULL);
if (unlikely(!result))
result = _Py_CheckFunctionResult(obj, result, NULL);
} else
#endif
result = __Pyx_PyObject_CallOneArg(method, obj); result = __Pyx_PyObject_CallOneArg(method, obj);
Py_DECREF(method); Py_DECREF(method);
return result; return result;
...@@ -1839,6 +1847,14 @@ static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name ...@@ -1839,6 +1847,14 @@ static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name
PyObject *method = NULL, *result; PyObject *method = NULL, *result;
int is_method = __Pyx_PyObject_GetMethod(obj, method_name, &method); int is_method = __Pyx_PyObject_GetMethod(obj, method_name, &method);
if (likely(is_method)) { if (likely(is_method)) {
#if PY_VERSION_HEX >= 0x030700A1 && CYTHON_UNPACK_METHODS && CYTHON_FAST_PYCCALL
if (Py_TYPE(method) == &PyMethodDescr_Type) {
PyMethodDescrObject *descr = (PyMethodDescrObject *)method;
result = _PyMethodDef_RawFastCallKeywords(descr->d_method, obj, &arg, 1, NULL);
if (unlikely(!result))
result = _Py_CheckFunctionResult(obj, result, NULL);
} else
#endif
result = __Pyx_PyObject_Call2Args(method, obj, arg); result = __Pyx_PyObject_Call2Args(method, obj, arg);
Py_DECREF(method); Py_DECREF(method);
return result; return result;
...@@ -1890,6 +1906,15 @@ static PyObject* __Pyx_PyObject_CallMethod2(PyObject* obj, PyObject* method_name ...@@ -1890,6 +1906,15 @@ static PyObject* __Pyx_PyObject_CallMethod2(PyObject* obj, PyObject* method_name
PyObject *args, *method = NULL, *result = NULL; PyObject *args, *method = NULL, *result = NULL;
int is_method = __Pyx_PyObject_GetMethod(obj, method_name, &method); int is_method = __Pyx_PyObject_GetMethod(obj, method_name, &method);
if (likely(is_method)) { if (likely(is_method)) {
#if PY_VERSION_HEX >= 0x030700A0 && CYTHON_UNPACK_METHODS && CYTHON_FAST_PYCCALL
if (Py_TYPE(method) == &PyMethodDescr_Type) {
PyMethodDescrObject *descr = (PyMethodDescrObject *)method;
PyObject *args[2] = {arg1, arg2};
result = _PyMethodDef_RawFastCallKeywords(descr->d_method, obj, args, 2, NULL);
if (unlikely(!result))
result = _Py_CheckFunctionResult(obj, result, NULL);
} else
#endif
result = __Pyx_PyObject_Call3Args(method, obj, arg1, arg2); result = __Pyx_PyObject_Call3Args(method, obj, arg1, arg2);
Py_DECREF(method); Py_DECREF(method);
return result; return result;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment