Commit bd023b4e authored by Stefan Behnel's avatar Stefan Behnel

Simplify some method calling code by providing a (better) fallback...

Simplify some method calling code by providing a (better) fallback implementation for "__Pyx_PyObject_GetMethod()".
parent 60b379c7
...@@ -120,7 +120,7 @@ static CYTHON_INLINE PyObject *__Pyx_Coroutine_GetAwaitableIter(PyObject *o); /* ...@@ -120,7 +120,7 @@ static CYTHON_INLINE PyObject *__Pyx_Coroutine_GetAwaitableIter(PyObject *o); /*
static PyObject *__Pyx__Coroutine_GetAwaitableIter(PyObject *o); /*proto*/ static PyObject *__Pyx__Coroutine_GetAwaitableIter(PyObject *o); /*proto*/
//////////////////// GetAwaitIter //////////////////// //////////////////// GetAwaitIter ////////////////////
//@requires: ObjectHandling.c::PyObjectGetAttrStr //@requires: ObjectHandling.c::PyObjectGetMethod
//@requires: ObjectHandling.c::PyObjectCallNoArg //@requires: ObjectHandling.c::PyObjectCallNoArg
//@requires: ObjectHandling.c::PyObjectCallOneArg //@requires: ObjectHandling.c::PyObjectCallOneArg
...@@ -191,19 +191,14 @@ static PyObject *__Pyx__Coroutine_GetAwaitableIter(PyObject *obj) { ...@@ -191,19 +191,14 @@ static PyObject *__Pyx__Coroutine_GetAwaitableIter(PyObject *obj) {
} else } else
#endif #endif
{ {
PyObject *method = __Pyx_PyObject_GetAttrStr(obj, PYIDENT("__await__")); PyObject *method = NULL;
if (unlikely(!method)) goto slot_error; int is_method = __Pyx_PyObject_GetMethod(obj, PYIDENT("__await__"), &method);
#if CYTHON_UNPACK_METHODS if (likely(is_method)) {
if (likely(PyMethod_Check(method))) { res = __Pyx_PyObject_CallOneArg(method, obj);
PyObject *self = PyMethod_GET_SELF(method); } else if (likely(method)) {
if (likely(self)) {
PyObject *function = PyMethod_GET_FUNCTION(method);
res = __Pyx_PyObject_CallOneArg(function, self);
} else
res = __Pyx_PyObject_CallNoArg(method);
} else
#endif
res = __Pyx_PyObject_CallNoArg(method); res = __Pyx_PyObject_CallNoArg(method);
} else
goto slot_error;
Py_DECREF(method); Py_DECREF(method);
} }
if (unlikely(!res)) { if (unlikely(!res)) {
......
...@@ -1404,17 +1404,14 @@ static CYTHON_INLINE int __Pyx_PyObject_SetAttrStr(PyObject* obj, PyObject* attr ...@@ -1404,17 +1404,14 @@ static CYTHON_INLINE int __Pyx_PyObject_SetAttrStr(PyObject* obj, PyObject* attr
/////////////// PyObjectGetMethod.proto /////////////// /////////////// PyObjectGetMethod.proto ///////////////
#if CYTHON_UNPACK_METHODS
static int __Pyx_PyObject_GetMethod(PyObject *obj, PyObject *name, PyObject **method);/*proto*/ static int __Pyx_PyObject_GetMethod(PyObject *obj, PyObject *name, PyObject **method);/*proto*/
#endif
/////////////// PyObjectGetMethod /////////////// /////////////// PyObjectGetMethod ///////////////
//@requires: PyObjectGetAttrStr //@requires: PyObjectGetAttrStr
#if CYTHON_UNPACK_METHODS
static int __Pyx_PyObject_GetMethod(PyObject *obj, PyObject *name, PyObject **method) { static int __Pyx_PyObject_GetMethod(PyObject *obj, PyObject *name, PyObject **method) {
PyObject *attr; PyObject *attr;
#if CYTHON_COMPILING_IN_CPYTHON && CYTHON_USE_PYTYPE_LOOKUP #if CYTHON_UNPACK_METHODS && CYTHON_COMPILING_IN_CPYTHON && CYTHON_USE_PYTYPE_LOOKUP
// Copied from _PyObject_GetMethod() in CPython 3.7 // Copied from _PyObject_GetMethod() in CPython 3.7
PyTypeObject *tp = Py_TYPE(obj); PyTypeObject *tp = Py_TYPE(obj);
PyObject *descr; PyObject *descr;
...@@ -1498,7 +1495,7 @@ static int __Pyx_PyObject_GetMethod(PyObject *obj, PyObject *name, PyObject **me ...@@ -1498,7 +1495,7 @@ static int __Pyx_PyObject_GetMethod(PyObject *obj, PyObject *name, PyObject **me
#endif #endif
try_unpack: try_unpack:
#if CYTHON_COMPILING_IN_CPYTHON #if CYTHON_UNPACK_METHODS
// Even if we failed to avoid creating a bound method object, it's still worth unpacking it now, if possible. // Even if we failed to avoid creating a bound method object, it's still worth unpacking it now, if possible.
if (likely(attr) && PyMethod_Check(attr) && likely(PyMethod_GET_SELF(attr) == obj)) { if (likely(attr) && PyMethod_Check(attr) && likely(PyMethod_GET_SELF(attr) == obj)) {
PyObject *function = PyMethod_GET_FUNCTION(attr); PyObject *function = PyMethod_GET_FUNCTION(attr);
...@@ -1511,7 +1508,6 @@ try_unpack: ...@@ -1511,7 +1508,6 @@ try_unpack:
*method = attr; *method = attr;
return 0; return 0;
} }
#endif
/////////////// UnpackUnboundCMethod.proto /////////////// /////////////// UnpackUnboundCMethod.proto ///////////////
...@@ -1741,22 +1737,17 @@ static PyObject* __Pyx_PyObject_CallMethod0(PyObject* obj, PyObject* method_name ...@@ -1741,22 +1737,17 @@ static PyObject* __Pyx_PyObject_CallMethod0(PyObject* obj, PyObject* method_name
/////////////// PyObjectCallMethod0 /////////////// /////////////// PyObjectCallMethod0 ///////////////
//@requires: PyObjectGetMethod //@requires: PyObjectGetMethod
//@requires: PyObjectGetAttrStr
//@requires: PyObjectCallOneArg //@requires: PyObjectCallOneArg
//@requires: PyObjectCallNoArg //@requires: PyObjectCallNoArg
static PyObject* __Pyx_PyObject_CallMethod0(PyObject* obj, PyObject* method_name) { static PyObject* __Pyx_PyObject_CallMethod0(PyObject* obj, PyObject* method_name) {
PyObject *method = NULL, *result = NULL; PyObject *method = NULL, *result = NULL;
#if CYTHON_UNPACK_METHODS
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)) {
result = __Pyx_PyObject_CallOneArg(method, obj); result = __Pyx_PyObject_CallOneArg(method, obj);
Py_DECREF(method); Py_DECREF(method);
return result; return result;
} }
#else
method = __Pyx_PyObject_GetAttrStr(obj, method_name);
#endif
if (unlikely(!method)) goto bad; if (unlikely(!method)) goto bad;
result = __Pyx_PyObject_CallNoArg(method); result = __Pyx_PyObject_CallNoArg(method);
Py_DECREF(method); Py_DECREF(method);
...@@ -1771,7 +1762,6 @@ static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name ...@@ -1771,7 +1762,6 @@ static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name
/////////////// PyObjectCallMethod1 /////////////// /////////////// PyObjectCallMethod1 ///////////////
//@requires: PyObjectGetMethod //@requires: PyObjectGetMethod
//@requires: PyObjectGetAttrStr
//@requires: PyObjectCallOneArg //@requires: PyObjectCallOneArg
//@requires: PyObjectCall2Args //@requires: PyObjectCall2Args
...@@ -1784,16 +1774,12 @@ static PyObject* __Pyx__PyObject_CallMethod1(PyObject* method, PyObject* arg) { ...@@ -1784,16 +1774,12 @@ static PyObject* __Pyx__PyObject_CallMethod1(PyObject* method, PyObject* arg) {
static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name, PyObject* arg) { static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name, PyObject* arg) {
PyObject *method = NULL, *result; PyObject *method = NULL, *result;
#if CYTHON_UNPACK_METHODS
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)) {
result = __Pyx_PyObject_Call2Args(method, obj, arg); result = __Pyx_PyObject_Call2Args(method, obj, arg);
Py_DECREF(method); Py_DECREF(method);
return result; return result;
} }
#else
method = __Pyx_PyObject_GetAttrStr(obj, method_name);
#endif
if (unlikely(!method)) return NULL; if (unlikely(!method)) return NULL;
return __Pyx__PyObject_CallMethod1(method, arg); return __Pyx__PyObject_CallMethod1(method, arg);
} }
...@@ -1804,13 +1790,11 @@ static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name ...@@ -1804,13 +1790,11 @@ static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name
static PyObject* __Pyx_PyObject_CallMethod2(PyObject* obj, PyObject* method_name, PyObject* arg1, PyObject* arg2); /*proto*/ static PyObject* __Pyx_PyObject_CallMethod2(PyObject* obj, PyObject* method_name, PyObject* arg1, PyObject* arg2); /*proto*/
/////////////// PyObjectCallMethod2 /////////////// /////////////// PyObjectCallMethod2 ///////////////
//@requires: PyObjectGetAttrStr
//@requires: PyObjectCall //@requires: PyObjectCall
//@requires: PyFunctionFastCall //@requires: PyFunctionFastCall
//@requires: PyCFunctionFastCall //@requires: PyCFunctionFastCall
//@requires: PyObjectCall2Args //@requires: PyObjectCall2Args
#if CYTHON_UNPACK_METHODS
static PyObject* __Pyx_PyObject_Call3Args(PyObject* function, PyObject* arg1, PyObject* arg2, PyObject* arg3) { static PyObject* __Pyx_PyObject_Call3Args(PyObject* function, PyObject* arg1, PyObject* arg2, PyObject* arg3) {
#if CYTHON_FAST_PYCALL #if CYTHON_FAST_PYCALL
if (PyFunction_Check(function)) { if (PyFunction_Check(function)) {
...@@ -1838,20 +1822,15 @@ static PyObject* __Pyx_PyObject_Call3Args(PyObject* function, PyObject* arg1, Py ...@@ -1838,20 +1822,15 @@ static PyObject* __Pyx_PyObject_Call3Args(PyObject* function, PyObject* arg1, Py
Py_DECREF(args); Py_DECREF(args);
return result; return result;
} }
#endif
static PyObject* __Pyx_PyObject_CallMethod2(PyObject* obj, PyObject* method_name, PyObject* arg1, PyObject* arg2) { static PyObject* __Pyx_PyObject_CallMethod2(PyObject* obj, PyObject* method_name, PyObject* arg1, PyObject* arg2) {
PyObject *args, *method = NULL, *result = NULL; PyObject *args, *method = NULL, *result = NULL;
#if CYTHON_UNPACK_METHODS
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)) {
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;
} }
#else
method = __Pyx_PyObject_GetAttrStr(obj, method_name);
#endif
if (unlikely(!method)) return NULL; if (unlikely(!method)) return NULL;
result = __Pyx_PyObject_Call2Args(method, arg1, arg2); result = __Pyx_PyObject_Call2Args(method, arg1, arg2);
Py_DECREF(method); Py_DECREF(method);
......
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