static Py_hash_t
unicode_hash(PyObject *self)
{
- Py_ssize_t len;
Py_uhash_t x; /* Unsigned for defined overflow behavior. */
#ifdef Py_DEBUG
return _PyUnicode_HASH(self);
if (PyUnicode_READY(self) == -1)
return -1;
- len = PyUnicode_GET_LENGTH(self);
- /*
- We make the hash of the empty string be 0, rather than using
- (prefix ^ suffix), since this slightly obfuscates the hash secret
- */
- if (len == 0) {
- _PyUnicode_HASH(self) = 0;
- return 0;
- }
+
x = _Py_HashBytes(PyUnicode_DATA(self),
PyUnicode_GET_LENGTH(self) * PyUnicode_KIND(self));
_PyUnicode_HASH(self) = x;