From 23350e5a905c38a75e3d10c66ec1f50f84f0e6e8 Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Sat, 16 Feb 2013 22:30:40 +0100 Subject: [PATCH] move __Pyx_GetName() into external utility file and make it use faster __Pyx_PyObject_GetAttrStr() --- Cython/Compiler/ExprNodes.py | 22 +--------------------- Cython/Utility/ObjectHandling.c | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index 2333d03..1af7eda 100755 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@ -10229,33 +10229,13 @@ class DocstringRefNode(ExprNode): code.put_gotref(self.result()) - #------------------------------------------------------------------------------------ # # Runtime support code # #------------------------------------------------------------------------------------ -get_name_interned_utility_code = UtilityCode( -proto = """ -static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/ -""", -impl = """ -static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name) { - PyObject *result; - result = PyObject_GetAttr(dict, name); - if (!result) { - if (dict != %(BUILTINS)s) { - PyErr_Clear(); - result = PyObject_GetAttr(%(BUILTINS)s, name); - } - if (!result) { - PyErr_SetObject(PyExc_NameError, name); - } - } - return result; -} -""" % {'BUILTINS' : Naming.builtins_cname}) +get_name_interned_utility_code = UtilityCode.load("GetGlobalName", "ObjectHandling.c") #------------------------------------------------------------------------------------ diff --git a/Cython/Utility/ObjectHandling.c b/Cython/Utility/ObjectHandling.c index 4fea755..30d1adf 100644 --- a/Cython/Utility/ObjectHandling.c +++ b/Cython/Utility/ObjectHandling.c @@ -586,6 +586,29 @@ static CYTHON_INLINE PyObject* __Pyx_PyBoolOrNull_FromLong(long b) { return unlikely(b < 0) ? NULL : __Pyx_PyBool_FromLong(b); } +/////////////// GetGlobalName.proto /////////////// + +static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/ + +/////////////// GetGlobalName /////////////// +//@requires: PyObjectGetAttrStr +//@substitute: naming + +static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name) { + PyObject *result; + result = __Pyx_PyObject_GetAttrStr(dict, name); + if (!result) { + if (dict != $builtins_cname) { + PyErr_Clear(); + result = __Pyx_PyObject_GetAttrStr($builtins_cname, name); + } + if (!result) { + PyErr_SetObject(PyExc_NameError, name); + } + } + return result; +} + /////////////// PyObjectGetAttrStr.proto /////////////// #if CYTHON_COMPILING_IN_CPYTHON -- 2.7.4