[pypy-svn] r15383 - pypy/dist/pypy/objspace/std
arigo at codespeak.net
arigo at codespeak.net
Fri Jul 29 22:53:23 CEST 2005
Author: arigo
Date: Fri Jul 29 22:53:21 2005
New Revision: 15383
Modified:
pypy/dist/pypy/objspace/std/dictobject.py
Log:
Don't use '%' in W_DictObject. Better use '&' masking, as we know the hash
table's length is a power of two. Additionally, genc doesn't know about '/'
and '%' on r_uint...
Modified: pypy/dist/pypy/objspace/std/dictobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/dictobject.py (original)
+++ pypy/dist/pypy/objspace/std/dictobject.py Fri Jul 29 22:53:21 2005
@@ -65,7 +65,8 @@
assert isinstance(lookup_hash, r_uint)
space = self.space
data = self.data
- i = lookup_hash % len(data)
+ mask = len(data) - 1 # len(data) is expected to be a power of 2
+ i = lookup_hash & mask
entry = data[i]
if entry.w_key is None or space.is_w(w_lookup, entry.w_key):
@@ -85,7 +86,7 @@
perturb = lookup_hash
while 1:
i = (i << 2) + i + perturb + 1
- entry = data[i%len(data)]
+ entry = data[i & mask]
if entry.w_key is None:
if freeslot:
return freeslot
More information about the Pypy-commit
mailing list