[pypy-svn] r26763 - pypy/dist/pypy/annotation

arigo at codespeak.net arigo at codespeak.net
Thu May 4 16:23:40 CEST 2006


Author: arigo
Date: Thu May  4 16:23:38 2006
New Revision: 26763

Modified:
   pypy/dist/pypy/annotation/bookkeeper.py
   pypy/dist/pypy/annotation/builtin.py
   pypy/dist/pypy/annotation/dictdef.py
Log:
r_dicts don't actually need the hash of their keys, as they delegate its
computation to callbacks.



Modified: pypy/dist/pypy/annotation/bookkeeper.py
==============================================================================
--- pypy/dist/pypy/annotation/bookkeeper.py	(original)
+++ pypy/dist/pypy/annotation/bookkeeper.py	Thu May  4 16:23:38 2006
@@ -274,12 +274,13 @@
             listdef.generalize(s_value)
         return SomeList(listdef)
 
-    def getdictdef(self):
+    def getdictdef(self, is_r_dict=False):
         """Get the DictDef associated with the current position."""
         try:
             dictdef = self.dictdefs[self.position_key]
         except KeyError:
-            dictdef = self.dictdefs[self.position_key] = DictDef(self)
+            dictdef = DictDef(self, is_r_dict=is_r_dict)
+            self.dictdefs[self.position_key] = dictdef
         return dictdef
 
     def newdict(self, *items_s):

Modified: pypy/dist/pypy/annotation/builtin.py
==============================================================================
--- pypy/dist/pypy/annotation/builtin.py	(original)
+++ pypy/dist/pypy/annotation/builtin.py	Thu May  4 16:23:38 2006
@@ -287,7 +287,7 @@
     return immutablevalue(True)
 
 def robjmodel_r_dict(s_eqfn, s_hashfn):
-    dictdef = getbookkeeper().getdictdef()
+    dictdef = getbookkeeper().getdictdef(is_r_dict=True)
     dictdef.dictkey.update_rdict_annotations(s_eqfn, s_hashfn)
     return SomeDict(dictdef)
 

Modified: pypy/dist/pypy/annotation/dictdef.py
==============================================================================
--- pypy/dist/pypy/annotation/dictdef.py	(original)
+++ pypy/dist/pypy/annotation/dictdef.py	Thu May  4 16:23:38 2006
@@ -7,8 +7,9 @@
 class DictKey(ListItem):
     custom_eq_hash = False
 
-    def __init__(self, bookkeeper, s_value):
+    def __init__(self, bookkeeper, s_value, is_r_dict=False):
         ListItem.__init__(self, bookkeeper, s_value)
+        self.is_r_dict = is_r_dict
         self.enable_hashing()
 
     def patch(self):
@@ -26,7 +27,8 @@
                                               other=other)
 
     def enable_hashing(self):
-        if isinstance(self.s_value, SomeInstance):
+        # r_dicts don't need the RPython hash of their keys
+        if isinstance(self.s_value, SomeInstance) and not self.is_r_dict:
             self.bookkeeper.needs_hash_support[self.s_value.classdef] = True
 
     def generalize(self, s_other_value):
@@ -90,8 +92,9 @@
     DictDef stores."""
 
     def __init__(self, bookkeeper, s_key = SomeImpossibleValue(),
-                                 s_value = SomeImpossibleValue()):
-        self.dictkey = DictKey(bookkeeper, s_key)
+                                 s_value = SomeImpossibleValue(),
+                               is_r_dict = False):
+        self.dictkey = DictKey(bookkeeper, s_key, is_r_dict)
         self.dictkey.itemof[self] = True
         self.dictvalue = DictValue(bookkeeper, s_value)
         self.dictvalue.itemof[self] = True



More information about the Pypy-commit mailing list