From: Neil Schemenauer Date: Fri, 7 Sep 2007 20:49:04 +0000 (+0000) Subject: Restore caching of unicode hash value. This apparently was broken X-Git-Tag: v3.0a2~422 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f8c37d16f31e18051ba6ba2643514cfcf9c89225;p=thirdparty%2FPython%2Fcpython.git Restore caching of unicode hash value. This apparently was broken during some refactoring. --- diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 76616b5ca97d..d52c080a593f 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -6588,12 +6588,19 @@ unicode_getitem(PyUnicodeObject *self, Py_ssize_t index) } static long -unicode_hash(PyObject *self) +unicode_hash(PyUnicodeObject *self) { - /* Since Unicode objects compare equal to their UTF-8 string - counterparts, we hash the UTF-8 string. */ - PyObject *v = _PyUnicode_AsDefaultEncodedString(self, NULL); - return PyObject_Hash(v); + if (self->hash != -1) { + return self->hash; + } + else { + /* Since Unicode objects compare equal to their UTF-8 string + counterparts, we hash the UTF-8 string. */ + PyObject *v = _PyUnicode_AsDefaultEncodedString((PyObject*)self, NULL); + long x = PyObject_Hash(v); + self->hash = x; + return x; + } } PyDoc_STRVAR(index__doc__,