summaryrefslogtreecommitdiffstats
path: root/Objects/bytesobject.c
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2011-11-21 19:46:33 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2011-11-21 19:46:33 (GMT)
commitce4a9da70535b4bb9048147b141f01004af2133d (patch)
tree853fa7484683a9c858f29bfab1320fb4baee5d98 /Objects/bytesobject.c
parent0a3229de6b80cfa9e432ef5a9c72548569503075 (diff)
downloadcpython-ce4a9da70535b4bb9048147b141f01004af2133d.zip
cpython-ce4a9da70535b4bb9048147b141f01004af2133d.tar.gz
cpython-ce4a9da70535b4bb9048147b141f01004af2133d.tar.bz2
Issue #13411: memoryview objects are now hashable when the underlying object is hashable.
Diffstat (limited to 'Objects/bytesobject.c')
-rw-r--r--Objects/bytesobject.c21
1 files changed, 5 insertions, 16 deletions
diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c
index a89798a..88411b7 100644
--- a/Objects/bytesobject.c
+++ b/Objects/bytesobject.c
@@ -860,22 +860,11 @@ bytes_richcompare(PyBytesObject *a, PyBytesObject *b, int op)
static Py_hash_t
bytes_hash(PyBytesObject *a)
{
- register Py_ssize_t len;
- register unsigned char *p;
- register Py_uhash_t x;
-
- if (a->ob_shash != -1)
- return a->ob_shash;
- len = Py_SIZE(a);
- p = (unsigned char *) a->ob_sval;
- x = (Py_uhash_t)*p << 7;
- while (--len >= 0)
- x = (1000003U*x) ^ (Py_uhash_t)*p++;
- x ^= (Py_uhash_t)Py_SIZE(a);
- if (x == -1)
- x = -2;
- a->ob_shash = x;
- return x;
+ if (a->ob_shash == -1) {
+ /* Can't fail */
+ a->ob_shash = _Py_HashBytes((unsigned char *) a->ob_sval, Py_SIZE(a));
+ }
+ return a->ob_shash;
}
static PyObject*