From 78e5a552bb0fa99c3fbd5b793da330e5d0cf7759 Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Tue, 23 Feb 2010 15:59:59 +0100 Subject: [PATCH] reverted PyDict_GetItem() implementation, replaced by selective optimisation in Py3 --- Cython/Compiler/ExprNodes.py | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index ef1d1b2c..fcd1970f 100755 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@ -6494,30 +6494,24 @@ static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void) { getitem_dict_utility_code = UtilityCode( proto = """ -static PyObject *__Pyx_PyDict_GetItem(PyObject *o, PyObject* key) { - long hash; - PyDictEntry *entry; +static PyObject *__Pyx_PyDict_GetItem(PyObject *d, PyObject* key) { PyObject *value; - if (unlikely(o == Py_None)) { + if (unlikely(d == Py_None)) { __Pyx_RaiseNoneIndexingError(); return NULL; } - if (!PyString_CheckExact(key) || - (hash = ((PyStringObject *) key)->ob_shash) == -1) { - hash = PyObject_Hash(key); - if (hash == -1) return NULL; - } - entry = ((PyDictObject*)o)->ma_lookup((PyDictObject*)o, key, hash); - if (likely(entry != NULL)) { - value = entry->me_value; - if (likely(value != NULL)) { - Py_INCREF(value); - return value; - } else { +#if PY_MAJOR_VERSION >= 3 + value = PyDict_GetItemWithError(d, key); + if (unlikely(!value)) { + if (!PyErr_Occurred()) PyErr_SetObject(PyExc_KeyError, key); - } + return NULL; } - return NULL; + Py_INCREF(value); +#else + value = PyObject_GetItem(d, key); +#endif + return value; } """, requires = [raise_noneindex_error_utility_code]) -- 2.26.2