[Python-3000-checkins] r58047 - python/branches/py3k/Objects/unicodeobject.c
neil.schemenauer
python-3000-checkins at python.org
Fri Sep 7 22:49:04 CEST 2007
Author: neil.schemenauer
Date: Fri Sep 7 22:49:04 2007
New Revision: 58047
Modified:
python/branches/py3k/Objects/unicodeobject.c
Log:
Restore caching of unicode hash value. This apparently was broken
during some refactoring.
Modified: python/branches/py3k/Objects/unicodeobject.c
==============================================================================
--- python/branches/py3k/Objects/unicodeobject.c (original)
+++ python/branches/py3k/Objects/unicodeobject.c Fri Sep 7 22:49:04 2007
@@ -6588,12 +6588,19 @@
}
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__,
More information about the Python-3000-checkins
mailing list