mirror of
https://github.com/python/cpython.git
synced 2025-07-31 23:23:11 +00:00
Restore caching of unicode hash value. This apparently was broken
during some refactoring.
This commit is contained in:
parent
02c305614d
commit
f8c37d16f3
1 changed files with 12 additions and 5 deletions
|
@ -6588,12 +6588,19 @@ unicode_getitem(PyUnicodeObject *self, Py_ssize_t index)
|
||||||
}
|
}
|
||||||
|
|
||||||
static long
|
static long
|
||||||
unicode_hash(PyObject *self)
|
unicode_hash(PyUnicodeObject *self)
|
||||||
{
|
{
|
||||||
/* Since Unicode objects compare equal to their UTF-8 string
|
if (self->hash != -1) {
|
||||||
counterparts, we hash the UTF-8 string. */
|
return self->hash;
|
||||||
PyObject *v = _PyUnicode_AsDefaultEncodedString(self, NULL);
|
}
|
||||||
return PyObject_Hash(v);
|
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__,
|
PyDoc_STRVAR(index__doc__,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue