From 0edf9e4cba649fc34f46c99c36fd7fcf15007a96 Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Thu, 11 Apr 2013 19:57:53 +0200 Subject: [PATCH] inline normal case of getattr(o,n) --HG-- extra : rebase_source : 9a5bbb4f08a0eb5be71afd48d9ad5566d8a39efc --- Cython/Compiler/Builtin.py | 8 +++++--- Cython/Utility/Builtins.c | 22 +++++++++++++++++++++- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/Cython/Compiler/Builtin.py b/Cython/Compiler/Builtin.py index ccafe60..1116d6e 100644 --- a/Cython/Compiler/Builtin.py +++ b/Cython/Compiler/Builtin.py @@ -13,6 +13,7 @@ import Options iter_next_utility_code = UtilityCode.load("IterNext", "ObjectHandling.c") getattr3_utility_code = UtilityCode.load("GetAttr3", "Builtins.c") +getattr_utility_code = UtilityCode.load("GetAttr", "Builtins.c") pyexec_utility_code = UtilityCode.load("PyExec", "Builtins.c") pyexec_globals_utility_code = UtilityCode.load("PyExecGlobals", "Builtins.c") globals_utility_code = UtilityCode.load("Globals", "Builtins.c") @@ -173,10 +174,11 @@ builtin_function_table = [ #('execfile', "", "", ""), #('filter', "", "", ""), BuiltinFunction('getattr3', "OOO", "O", "__Pyx_GetAttr3", "getattr", - utility_code = getattr3_utility_code), # Pyrex compatibility + utility_code=getattr3_utility_code), # Pyrex legacy BuiltinFunction('getattr', "OOO", "O", "__Pyx_GetAttr3", - utility_code = getattr3_utility_code), - BuiltinFunction('getattr', "OO", "O", "PyObject_GetAttr"), + utility_code=getattr3_utility_code), + BuiltinFunction('getattr', "OO", "O", "__Pyx_GetAttr", + utility_code=getattr_utility_code), BuiltinFunction('hasattr', "OO", "b", "PyObject_HasAttr"), BuiltinFunction('hash', "O", "h", "PyObject_Hash"), #('hex', "", "", ""), diff --git a/Cython/Utility/Builtins.c b/Cython/Utility/Builtins.c index cc2d6ec..75432a6 100644 --- a/Cython/Utility/Builtins.c +++ b/Cython/Utility/Builtins.c @@ -164,14 +164,34 @@ bad: return 0; } +//////////////////// GetAttr.proto //////////////////// + +static CYTHON_INLINE PyObject *__Pyx_GetAttr(PyObject *, PyObject *); /*proto*/ + +//////////////////// GetAttr //////////////////// +//@requires: ObjectHandling.c::PyObjectGetAttrStr + +static CYTHON_INLINE PyObject *__Pyx_GetAttr(PyObject *o, PyObject *n) { +#if CYTHON_COMPILING_IN_CPYTHON +#if PY_MAJOR_VERSION >= 3 + if (likely(PyUnicode_Check(n))) +#else + if (likely(PyString_Check(n))) +#endif + return __Pyx_PyObject_GetAttrStr(o, n); +#endif + return PyObject_GetAttr(o, n); +} + //////////////////// GetAttr3.proto //////////////////// static CYTHON_INLINE PyObject *__Pyx_GetAttr3(PyObject *, PyObject *, PyObject *); /*proto*/ //////////////////// GetAttr3 //////////////////// +//@requires: GetAttr static CYTHON_INLINE PyObject *__Pyx_GetAttr3(PyObject *o, PyObject *n, PyObject *d) { - PyObject *r = PyObject_GetAttr(o, n); + PyObject *r = __Pyx_GetAttr(o, n); if (!r) { if (!PyErr_ExceptionMatches(PyExc_AttributeError)) goto bad; -- 2.7.4