Commit 7454b282 authored by Stefan Behnel's avatar Stefan Behnel

Remove direct Unicode hash usage for dict lookups as it proved to be slower...

Remove direct Unicode hash usage for dict lookups as it proved to be slower after all. Optimising a generic item lookup for dict is faster, though.
parent d07280ba
...@@ -3897,16 +3897,12 @@ class IndexNode(_IndexingBaseNode): ...@@ -3897,16 +3897,12 @@ class IndexNode(_IndexingBaseNode):
utility_code = TempitaUtilityCode.load_cached("GetItemInt", "ObjectHandling.c") utility_code = TempitaUtilityCode.load_cached("GetItemInt", "ObjectHandling.c")
else: else:
if self.base.type is dict_type: if self.base.type is dict_type:
if self.index.type in (str_type, unicode_type): function = "__Pyx_PyDict_GetItem"
function = "__Pyx_PyDict_GetItemUnicode" utility_code = UtilityCode.load_cached("DictGetItem", "ObjectHandling.c")
utility_code = UtilityCode.load_cached("DictGetItemUnicode", "ObjectHandling.c") elif self.base.type is py_object_type and self.index.type in (str_type, unicode_type):
else:
function = "__Pyx_PyDict_GetItem"
utility_code = UtilityCode.load_cached("DictGetItem", "ObjectHandling.c")
elif self.index.type in (str_type, unicode_type):
# obj[str] is probably doing a dict lookup # obj[str] is probably doing a dict lookup
function = "__Pyx_PyObject_GetItemUnicode" function = "__Pyx_PyObject_Dict_GetItem"
utility_code = UtilityCode.load_cached("DictGetItemUnicode", "ObjectHandling.c") utility_code = UtilityCode.load_cached("DictGetItem", "ObjectHandling.c")
else: else:
function = "PyObject_GetItem" function = "PyObject_GetItem"
elif self.type.is_unicode_char and self.base.type is unicode_type: elif self.type.is_unicode_char and self.base.type is unicode_type:
......
...@@ -262,55 +262,18 @@ static CYTHON_INLINE int __Pyx_IterFinish(void) { ...@@ -262,55 +262,18 @@ static CYTHON_INLINE int __Pyx_IterFinish(void) {
#endif #endif
} }
/////////////// DictGetItemUnicode.proto /////////////// /////////////// DictGetItem.proto ///////////////
//@requires: DictGetItem
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1 && CYTHON_USE_UNICODE_INTERNALS
static CYTHON_INLINE PyObject *__Pyx__PyDict_GetItemUnicode(PyObject *d, PyObject* key);
#define __Pyx_PyDict_GetItemUnicode(d, key) \
(likely(PyUnicode_CheckExact(key) && ((PyASCIIObject *) key)->hash != -1) ? \
__Pyx__PyDict_GetItemUnicode(d, key) : __Pyx_PyDict_GetItem(d, key))
#define __Pyx_PyObject_GetItemUnicode(obj, name) \
(likely(PyDict_CheckExact(obj)) ? \
__Pyx_PyDict_GetItemUnicode(obj, name) : PyObject_GetItem(obj, name))
#else /* Py < 3.5 */
#define __Pyx_PyDict_GetItemUnicode(d, key) __Pyx_PyDict_GetItem(d, key)
#if PY_MAJOR_VERSION >= 3 && !CYTHON_COMPILING_IN_PYPY #if PY_MAJOR_VERSION >= 3 && !CYTHON_COMPILING_IN_PYPY
#define __Pyx_PyObject_GetItemUnicode(obj, name) \ static PyObject *__Pyx_PyDict_GetItem(PyObject *d, PyObject* key);/*proto*/
#define __Pyx_PyObject_Dict_GetItem(obj, name) \
(likely(PyDict_CheckExact(obj)) ? \ (likely(PyDict_CheckExact(obj)) ? \
__Pyx_PyDict_GetItem(obj, name) : PyObject_GetItem(obj, name)) __Pyx_PyDict_GetItem(obj, name) : PyObject_GetItem(obj, name))
#else
#define __Pyx_PyObject_GetItemUnicode(obj, name) PyObject_GetItem(obj, name)
#endif
#endif
/////////////// DictGetItemUnicode ///////////////
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1 && CYTHON_USE_UNICODE_INTERNALS
static PyObject *__Pyx__PyDict_GetItemUnicode(PyObject *d, PyObject* key) {
PyObject *value;
value = __Pyx_PyDict_GetItemStr(d, key);
if (unlikely(!value)) {
PyErr_SetObject(PyExc_KeyError, key);
return NULL;
}
Py_INCREF(value);
return value;
}
#endif
/////////////// DictGetItem.proto ///////////////
#if PY_MAJOR_VERSION >= 3 && !CYTHON_COMPILING_IN_PYPY
static PyObject *__Pyx_PyDict_GetItem(PyObject *d, PyObject* key);/*proto*/
#else #else
#define __Pyx_PyDict_GetItem(d, key) PyObject_GetItem(d, key) #define __Pyx_PyDict_GetItem(d, key) PyObject_GetItem(d, key)
#define __Pyx_PyObject_Dict_GetItem(obj, name) PyObject_GetItem(obj, name)
#endif #endif
/////////////// DictGetItem /////////////// /////////////// DictGetItem ///////////////
......
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