]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Restore caching of unicode hash value. This apparently was broken
authorNeil Schemenauer <nascheme@enme.ucalgary.ca>
Fri, 7 Sep 2007 20:49:04 +0000 (20:49 +0000)
committerNeil Schemenauer <nascheme@enme.ucalgary.ca>
Fri, 7 Sep 2007 20:49:04 +0000 (20:49 +0000)
during some refactoring.

Objects/unicodeobject.c

index 76616b5ca97dd2da1b1389c1b55af8b4cfba664e..d52c080a593f4550e0919520d6ebf51af6032b2f 100644 (file)
@@ -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__,