[pypy-svn] r77120 - in pypy/branch/better-map-instances/pypy: interpreter objspace/std objspace/std/test

cfbolz at codespeak.net cfbolz at codespeak.net
Thu Sep 16 16:53:17 CEST 2010


Author: cfbolz
Date: Thu Sep 16 16:53:15 2010
New Revision: 77120

Modified:
   pypy/branch/better-map-instances/pypy/interpreter/typedef.py
   pypy/branch/better-map-instances/pypy/objspace/std/mapdict.py
   pypy/branch/better-map-instances/pypy/objspace/std/objspace.py
   pypy/branch/better-map-instances/pypy/objspace/std/test/test_mapdict.py
Log:
maybe this has a chance to work


Modified: pypy/branch/better-map-instances/pypy/interpreter/typedef.py
==============================================================================
--- pypy/branch/better-map-instances/pypy/interpreter/typedef.py	(original)
+++ pypy/branch/better-map-instances/pypy/interpreter/typedef.py	Thu Sep 16 16:53:15 2010
@@ -193,14 +193,15 @@
 
     def add(Proto):
         for key, value in Proto.__dict__.items():
-            if not key.startswith('__') or key == '__del__':
+            if not key.startswith('__') or key in ['__del__', '_mixin_']:
                 if hasattr(value, "func_name"):
                     value = func_with_new_name(value, value.func_name)
                 body[key] = value
 
     if (config.objspace.std.withmapdict and "dict" in features):
-        from pypy.objspace.std.mapdict import BaseMapdictObject
+        from pypy.objspace.std.mapdict import BaseMapdictObject, ObjectMixin
         add(BaseMapdictObject)
+        add(ObjectMixin)
         features = ()
 
     if "user" in features:     # generic feature needed by all subcls

Modified: pypy/branch/better-map-instances/pypy/objspace/std/mapdict.py
==============================================================================
--- pypy/branch/better-map-instances/pypy/objspace/std/mapdict.py	(original)
+++ pypy/branch/better-map-instances/pypy/objspace/std/mapdict.py	Thu Sep 16 16:53:15 2010
@@ -272,7 +272,9 @@
 SLOTS_STARTING_FROM = 3
 
 
-class BaseMapdictObject(W_Root): # slightly evil to make it inherit from W_Root
+class BaseMapdictObject: # slightly evil to make it inherit from W_Root
+    _mixin_ = True # XXX hack hack hack
+
     def _init_empty(self, map):
         raise NotImplementedError("abstract base class")
 
@@ -373,13 +375,13 @@
     def _set_mapdict_storage(self, storage):
         self.storage = storage
 
-class Object(ObjectMixin, BaseMapdictObject):
+class Object(ObjectMixin, BaseMapdictObject, W_Root):
     pass # mainly for tests
 
-def get_subclass_of_correct_size(space, cls, supercls, w_type):
+def get_subclass_of_correct_size(space, cls, w_type):
     assert space.config.objspace.std.withmapdict
     map = w_type.terminator
-    classes = memo_get_subclass_of_correct_size(space, supercls)
+    classes = memo_get_subclass_of_correct_size(space, cls)
     size = map.size_estimate()
     if not size:
         size = 1
@@ -396,18 +398,10 @@
     try:
         return _subclass_cache[key]
     except KeyError:
-	if not hasattr(supercls, "_init_empty"):
-            result = [supercls] * NUM_SUBCLASSES # not a mapdict
-        if (not issubclass(supercls, W_ObjectObject) or
-                hasattr(supercls, '__del__')):
-            class subcls(ObjectMixin, supercls):
-                pass
-            subcls.__name__ = supercls.__name__ + "Concrete"
-            result = [subcls] * NUM_SUBCLASSES
-        else:
-            result = []
-            for i in range(1, NUM_SUBCLASSES+1):
-                result.append(_make_subclass_size_n(supercls, i))
+        assert not hasattr(supercls, "__del__")
+        result = []
+        for i in range(1, NUM_SUBCLASSES+1):
+            result.append(_make_subclass_size_n(supercls, i))
         _subclass_cache[key] = result
         return result
 memo_get_subclass_of_correct_size._annspecialcase_ = "specialize:memo"
@@ -418,7 +412,7 @@
     rangen = unroll.unrolling_iterable(range(n))
     nmin1 = n - 1
     rangenmin1 = unroll.unrolling_iterable(range(nmin1))
-    class subcls(supercls):
+    class subcls(ObjectMixin, BaseMapdictObject, supercls):
         def _init_empty(self, map):
             from pypy.rlib.debug import make_sure_not_resized
             for i in rangen:

Modified: pypy/branch/better-map-instances/pypy/objspace/std/objspace.py
==============================================================================
--- pypy/branch/better-map-instances/pypy/objspace/std/objspace.py	(original)
+++ pypy/branch/better-map-instances/pypy/objspace/std/objspace.py	Thu Sep 16 16:53:15 2010
@@ -23,6 +23,7 @@
 from pypy.objspace.std.listobject import W_ListObject
 from pypy.objspace.std.longobject import W_LongObject
 from pypy.objspace.std.noneobject import W_NoneObject
+from pypy.objspace.std.objectobject import W_ObjectObject
 from pypy.objspace.std.ropeobject import W_RopeObject
 from pypy.objspace.std.iterobject import W_SeqIterObject
 from pypy.objspace.std.setobject import W_SetObject, W_FrozensetObject
@@ -318,12 +319,14 @@
             w_subtype = w_type.check_user_subclass(w_subtype)
             if cls.typedef.applevel_subclasses_base is not None:
                 cls = cls.typedef.applevel_subclasses_base
-            subcls = get_unique_interplevel_subclass(
-                    self.config, cls, w_subtype.hasdict, w_subtype.nslots != 0,
-                    w_subtype.needsdel, w_subtype.weakrefable)
-            if self.config.objspace.std.withmapdict:
+            if (self.config.objspace.std.withmapdict and cls is W_ObjectObject
+                    and not w_subtype.needsdel):
                 from pypy.objspace.std.mapdict import get_subclass_of_correct_size
-                subcls = get_subclass_of_correct_size(self, cls, subcls, w_subtype)
+                subcls = get_subclass_of_correct_size(self, cls, w_subtype)
+            else:
+                subcls = get_unique_interplevel_subclass(
+                        self.config, cls, w_subtype.hasdict, w_subtype.nslots != 0,
+                        w_subtype.needsdel, w_subtype.weakrefable)
             instance = instantiate(subcls)
             assert isinstance(instance, cls)
             instance.user_setup(self, w_subtype)

Modified: pypy/branch/better-map-instances/pypy/objspace/std/test/test_mapdict.py
==============================================================================
--- pypy/branch/better-map-instances/pypy/objspace/std/test/test_mapdict.py	(original)
+++ pypy/branch/better-map-instances/pypy/objspace/std/test/test_mapdict.py	Thu Sep 16 16:53:15 2010
@@ -360,10 +360,7 @@
 def test_specialized_class():
     from pypy.objspace.std.objectobject import W_ObjectObject
     from pypy.rlib import rerased
-    class Object(BaseMapdictObject, W_ObjectObject): # slightly evil
-        class typedef:
-            hasdict = False
-    classes = memo_get_subclass_of_correct_size(space, Object)
+    classes = memo_get_subclass_of_correct_size(space, W_ObjectObject)
     w1 = W_Root()
     w2 = W_Root()
     w3 = W_Root()



More information about the Pypy-commit mailing list