Author: Lukas Diekmann <[email protected]>
Branch: dict-strategies
Changeset: r44458:4986ec1afa46
Date: 2011-04-15 15:17 +0200
http://bitbucket.org/pypy/pypy/changeset/4986ec1afa46/

Log:    fixed WaryDict to use strategies; tests in
        module/__builtin__/test_builtin.py work again

diff --git a/pypy/objspace/std/dictmultiobject.py 
b/pypy/objspace/std/dictmultiobject.py
--- a/pypy/objspace/std/dictmultiobject.py
+++ b/pypy/objspace/std/dictmultiobject.py
@@ -50,7 +50,8 @@
 
         elif space.config.objspace.opcodes.CALL_LIKELY_BUILTIN and module:
             assert w_type is None
-            strategy = space.fromcache(WaryDictStrategy)
+            # create new Strategy everytime, because each must have its own 
shadow-attribute
+            strategy = WaryDictStrategy(space)
 
         elif space.config.objspace.std.withdictmeasurement:
             assert w_type is None
@@ -105,7 +106,7 @@
                     getitem_str delitem length \
                     clear keys values \
                     items iter setdefault \
-                    popitem".split()
+                    popitem get_builtin_indexed".split()
 
     def make_method(method):
         def f(self, *args):
@@ -161,6 +162,11 @@
             else:
                 return result
 
+    def get_builtin_indexed(self, w_dict, i):
+        key = OPTIMIZED_BUILTINS[i]
+        return self.getitem_str(w_dict, key)
+
+
     # _________________________________________________________________
     # implementation methods
 
@@ -232,6 +238,9 @@
     def impl_clear(self, w_dict):
         self.r_dict_content = None
 
+    def clear(self, w_dict):
+        return
+
     def _as_rdict(self):
         r_dict_content = self.initialize_as_rdict()
         return self
@@ -306,12 +315,9 @@
                     for w_key, w_val in 
self.cast_from_void_star(w_dict.dstorage).iteritems()]
 
     def clear(self, w_dict):
+        #XXX switch to empty
         self.cast_from_void_star(w_dict.dstorage).clear()
 
-    def impl_get_builtin_indexed(self, w_dict, i):
-        key = OPTIMIZED_BUILTINS[i]
-        return self.impl_fallback_getitem_str(key)
-
     def popitem(self, w_dict):
         return self.cast_from_void_star(w_dict.dstorage).popitem()
 
@@ -482,21 +488,22 @@
 
 class WaryDictStrategy(StringDictStrategy):
     def __init__(self, space):
-        StrDictImplementation.__init__(self, space)
+        StringDictStrategy.__init__(self, space)
         self.shadowed = [None] * len(BUILTIN_TO_INDEX)
 
-    def impl_setitem_str(self, w_dict, key, w_value):
+    def setitem_str(self, w_dict, key, w_value):
         i = BUILTIN_TO_INDEX.get(key, -1)
         if i != -1:
             self.shadowed[i] = w_value
-        self.content[key] = w_value
+        self.cast_from_void_star(w_dict.dstorage)[key] = w_value
+        #self.content[key] = w_value
 
-    def impl_delitem(self, w_dict, w_key):
+    def delitem(self, w_dict, w_key):
         space = self.space
         w_key_type = space.type(w_key)
         if space.is_w(w_key_type, space.w_str):
             key = space.str_w(w_key)
-            del self.content[key]
+            del self.cast_from_void_star(w_dict.dstorage)[key]
             i = BUILTIN_TO_INDEX.get(key, -1)
             if i != -1:
                 self.shadowed[i] = None
@@ -505,7 +512,7 @@
         else:
             self._as_rdict().impl_fallback_delitem(w_key)
 
-    def impl_get_builtin_indexed(self, w_dict, i):
+    def get_builtin_indexed(self, w_dict, i):
         return self.shadowed[i]
 
 
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to