Author: Kunal Grover <[email protected]>
Branch: py3.3-hashfix
Changeset: r83697:7aa21c0ec926
Date: 2016-02-19 00:54 +0530
http://bitbucket.org/pypy/pypy/changeset/7aa21c0ec926/
Log: Use intobject hash function for specialisedtuple
diff --git a/pypy/objspace/std/intobject.py b/pypy/objspace/std/intobject.py
--- a/pypy/objspace/std/intobject.py
+++ b/pypy/objspace/std/intobject.py
@@ -1028,3 +1028,20 @@
__pow__ = interpindirect2app(W_AbstractIntObject.descr_pow),
__rpow__ = interpindirect2app(W_AbstractIntObject.descr_rpow),
)
+
+
+def _hash_int(space, a):
+ sign = 1
+ if a < 0:
+ sign = -1
+ a = -a
+
+ x = r_uint(a)
+ # efficient x % HASH_MODULUS: as HASH_MODULUS is a Mersenne
+ # prime
+ x = (x & HASH_MODULUS) + (x >> HASH_BITS)
+ if x >= HASH_MODULUS:
+ x -= HASH_MODULUS
+
+ x = intmask(intmask(x) * sign)
+ return -2 if x == -1 else x
diff --git a/pypy/objspace/std/specialisedtupleobject.py
b/pypy/objspace/std/specialisedtupleobject.py
--- a/pypy/objspace/std/specialisedtupleobject.py
+++ b/pypy/objspace/std/specialisedtupleobject.py
@@ -67,6 +67,11 @@
# integer & other less frequent cases
from pypy.objspace.std.floatobject import _hash_float
y = _hash_float(space, value)
+ elif typetuple[i] == int:
+ # hash for int which is different from the hash
+ # given by rpython
+ from pypy.objspace.std.intobject import _hash_int
+ y = _hash_int(space, value)
else:
y = compute_hash(value)
x = (x ^ y) * mult
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit