diff options
author | Christian Heimes <christian@cheimes.de> | 2013-11-20 11:46:18 +0100 |
---|---|---|
committer | Christian Heimes <christian@cheimes.de> | 2013-11-20 11:46:18 +0100 |
commit | 985ecdcfc29adfc36ce2339acf03f819ad414869 (patch) | |
tree | 06a11f82271e768dbe49469c8736b65b083f671c /Objects/unicodeobject.c | |
parent | fe32aec25a8b36498d840bd69485e9bc94195b9c (diff) | |
download | cpython-git-985ecdcfc29adfc36ce2339acf03f819ad414869.tar.gz |
ssue #19183: Implement PEP 456 'secure and interchangeable hash algorithm'.
Python now uses SipHash24 on all major platforms.
Diffstat (limited to 'Objects/unicodeobject.c')
-rw-r--r-- | Objects/unicodeobject.c | 35 |
1 files changed, 2 insertions, 33 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 880889e8a2..3644db3b13 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -11386,39 +11386,8 @@ unicode_hash(PyObject *self) _PyUnicode_HASH(self) = 0; return 0; } - - /* The hash function as a macro, gets expanded three times below. */ -#define HASH(P) \ - x ^= (Py_uhash_t) *P << 7; \ - while (--len >= 0) \ - x = (_PyHASH_MULTIPLIER * x) ^ (Py_uhash_t) *P++; \ - - x = (Py_uhash_t) _Py_HashSecret.prefix; - switch (PyUnicode_KIND(self)) { - case PyUnicode_1BYTE_KIND: { - const unsigned char *c = PyUnicode_1BYTE_DATA(self); - HASH(c); - break; - } - case PyUnicode_2BYTE_KIND: { - const Py_UCS2 *s = PyUnicode_2BYTE_DATA(self); - HASH(s); - break; - } - default: { - Py_UCS4 *l; - assert(PyUnicode_KIND(self) == PyUnicode_4BYTE_KIND && - "Impossible switch case in unicode_hash"); - l = PyUnicode_4BYTE_DATA(self); - HASH(l); - break; - } - } - x ^= (Py_uhash_t) PyUnicode_GET_LENGTH(self); - x ^= (Py_uhash_t) _Py_HashSecret.suffix; - - if (x == -1) - x = -2; + x = _Py_HashBytes(PyUnicode_DATA(self), + PyUnicode_GET_LENGTH(self) * PyUnicode_KIND(self)); _PyUnicode_HASH(self) = x; return x; } |