[pypy-svn] r24879 - pypy/dist/pypy/rpython

arigo at codespeak.net arigo at codespeak.net
Thu Mar 23 13:44:06 CET 2006


Author: arigo
Date: Thu Mar 23 13:44:05 2006
New Revision: 24879

Modified:
   pypy/dist/pypy/rpython/rdict.py
Log:
Only check if the dictionary was mutated by the call to
keyeq() in the case of r_dict()s, not for normal RPython
dicts.  Indeed, none of the get_ll_eq_function() so far has
visible side effects.



Modified: pypy/dist/pypy/rpython/rdict.py
==============================================================================
--- pypy/dist/pypy/rpython/rdict.py	(original)
+++ pypy/dist/pypy/rpython/rdict.py	Thu Mar 23 13:44:05 2006
@@ -194,6 +194,7 @@
                     'keyeq':          ll_keyeq_custom,
                     'r_rdict_eqfn':   self.r_rdict_eqfn,
                     'r_rdict_hashfn': self.r_rdict_hashfn,
+                    'paranoia':       True,
                     }
             else:
                 # figure out which functions must be used to hash and compare
@@ -203,8 +204,9 @@
                 if ll_keyeq is not None:
                     ll_keyeq = lltype.staticAdtMethod(ll_keyeq)
                 adtmeths = {
-                    'keyhash': ll_keyhash,
-                    'keyeq':   ll_keyeq,
+                    'keyhash':  ll_keyhash,
+                    'keyeq':    ll_keyeq,
+                    'paranoia': False,
                     }
             self.DICT.become(lltype.GcStruct("dicttable", adtmeths=adtmeths,
                                              *fields))
@@ -507,6 +509,7 @@
 PERTURB_SHIFT = 5
 
 def ll_dict_lookup(d, key, hash):
+    DICT = lltype.typeOf(d).TO
     entries = d.entries
     mask = len(entries) - 1
     i = r_uint(hash & mask) 
@@ -520,7 +523,7 @@
             # correct hash, maybe the key is e.g. a different pointer to
             # an equal object
             found = d.keyeq(checkingkey, key)
-            if 1:      # XXX not always needed
+            if DICT.paranoia:
                 if (entries != d.entries or
                     not entry.valid() or entry.key != checkingkey):
                     # the compare did major nasty stuff to the dict: start over
@@ -549,7 +552,7 @@
                 # correct hash, maybe the key is e.g. a different pointer to
                 # an equal object
                 found = d.keyeq(checkingkey, key)
-                if 1:      # XXX not always needed
+                if DICT.paranoia:
                     if (entries != d.entries or
                         not entry.valid() or entry.key != checkingkey):
                         # the compare did major nasty stuff to the dict:



More information about the Pypy-commit mailing list