return x;
}
+Py_hash_t
+_Py_HashBytes(unsigned char *p, Py_ssize_t len)
+{
+ Py_uhash_t x;
+ Py_ssize_t i;
+
+ /*
+ We make the hash of the empty string be 0, rather than using
+ (prefix ^ suffix), since this slightly obfuscates the hash secret
+ */
++ assert(_Py_HashSecret_Initialized);
+ if (len == 0) {
+ return 0;
+ }
+ x = (Py_uhash_t) _Py_HashSecret.prefix;
+ x ^= (Py_uhash_t) *p << 7;
+ for (i = 0; i < len; i++)
+ x = (_PyHASH_MULTIPLIER * x) ^ (Py_uhash_t) *p++;
+ x ^= (Py_uhash_t) len;
+ x ^= (Py_uhash_t) _Py_HashSecret.suffix;
+ if (x == -1)
+ x = -2;
+ return x;
+}
+
Py_hash_t
PyObject_HashNotImplemented(PyObject *v)
{
}
/* Believe it or not, this produces the same value for ASCII strings
- as string_hash(). */
+ as bytes_hash(). */
static Py_hash_t
-unicode_hash(PyUnicodeObject *self)
+unicode_hash(PyObject *self)
{
Py_ssize_t len;
- Py_UNICODE *p;
- Py_hash_t x;
+ Py_uhash_t x;
- if (self->hash != -1)
- return self->hash;
- len = Py_SIZE(self);
+ assert(_Py_HashSecret_Initialized);
+ if (_PyUnicode_HASH(self) != -1)
+ 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