Mercurial > cpython-lru_cache-weakref
diff Objects/unicodeobject.c @ 43289:e85faa02191c
Restore caching of unicode hash value. This apparently was broken
during some refactoring.
| author | Neil Schemenauer <nascheme@enme.ucalgary.ca> |
|---|---|
| date | Fri, 07 Sep 2007 20:49:04 +0000 |
| parents | 275f894dbf12 |
| children | 4e543fae0ded |
line wrap: on
line diff
--- a/Objects/unicodeobject.c Fri Sep 07 17:52:53 2007 +0000 +++ b/Objects/unicodeobject.c Fri Sep 07 20:49:04 2007 +0000 @@ -6588,12 +6588,19 @@ } static long -unicode_hash(PyObject *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); +unicode_hash(PyUnicodeObject *self) +{ + 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__,
