summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorNeil Schemenauer <nascheme@enme.ucalgary.ca>2007-09-07 20:49:04 (GMT)
committerNeil Schemenauer <nascheme@enme.ucalgary.ca>2007-09-07 20:49:04 (GMT)
commitf8c37d16f31e18051ba6ba2643514cfcf9c89225 (patch)
tree320b2607e4abd74e7ce1177d46bf21589c57e723 /Objects
parent02c305614d0dccee7deeda471942992c72cdc8f1 (diff)
downloadcpython-f8c37d16f31e18051ba6ba2643514cfcf9c89225.zip
cpython-f8c37d16f31e18051ba6ba2643514cfcf9c89225.tar.gz
cpython-f8c37d16f31e18051ba6ba2643514cfcf9c89225.tar.bz2
Restore caching of unicode hash value. This apparently was broken
during some refactoring.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/unicodeobject.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 76616b5..d52c080 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__,