[pypy-svn] r70898 - in pypy/trunk/pypy: interpreter module/__builtin__/test objspace/std

cfbolz at codespeak.net cfbolz at codespeak.net
Tue Jan 26 18:45:49 CET 2010


Author: cfbolz
Date: Tue Jan 26 18:45:48 2010
New Revision: 70898

Modified:
   pypy/trunk/pypy/interpreter/pyframe.py
   pypy/trunk/pypy/module/__builtin__/test/test_classobj.py
   pypy/trunk/pypy/objspace/std/dictmultiobject.py
   pypy/trunk/pypy/objspace/std/objspace.py
Log:
Improve slightly on old-style classes (and on the execution time of all class
bodies): make the __dict__ of an old-style class a str-dict.


Modified: pypy/trunk/pypy/interpreter/pyframe.py
==============================================================================
--- pypy/trunk/pypy/interpreter/pyframe.py	(original)
+++ pypy/trunk/pypy/interpreter/pyframe.py	Tue Jan 26 18:45:48 2010
@@ -110,7 +110,7 @@
         if flags & pycode.CO_OPTIMIZED: 
             return 
         if flags & pycode.CO_NEWLOCALS:
-            self.w_locals = self.space.newdict()
+            self.w_locals = self.space.newdict(strdict=True)
         else:
             assert self.w_globals is not None
             self.w_locals = self.w_globals

Modified: pypy/trunk/pypy/module/__builtin__/test/test_classobj.py
==============================================================================
--- pypy/trunk/pypy/module/__builtin__/test/test_classobj.py	(original)
+++ pypy/trunk/pypy/module/__builtin__/test/test_classobj.py	Tue Jan 26 18:45:48 2010
@@ -773,9 +773,9 @@
         if option.runappdirect:
             py.test.skip("can only be run on py.py")
         def is_sharing(space, w_inst):
-            from pypy.objspace.std.sharingdict import SharedDictImplementation, W_DictMultiObject
+            from pypy.objspace.std.sharingdict import SharedDictImplementation
             w_d = w_inst.getdict()
-            return space.wrap(isinstance(w_d, SharedDictImplementation))
+            return space.wrap(isinstance(w_d, SharedDictImplementation) and w_d.r_dict_content is None)
         cls.w_is_sharing = cls.space.wrap(gateway.interp2app(is_sharing))
 
 
@@ -786,3 +786,22 @@
         A1, A2, A3 = A(), A(), A()
         assert self.is_sharing(A3)
         assert self.is_sharing(A2)
+        assert self.is_sharing(A1)
+
+class AppTestOldStyleStrDict(object):
+    def setup_class(cls):
+        cls.space = gettestobjspace()
+        if option.runappdirect:
+            py.test.skip("can only be run on py.py")
+        def is_strdict(space, w_class):
+            from pypy.objspace.std.dictmultiobject import StrDictImplementation
+            w_d = w_class.getdict()
+            return space.wrap(isinstance(w_d, StrDictImplementation) and w_d.r_dict_content is None)
+
+        cls.w_is_strdict = cls.space.wrap(gateway.interp2app(is_strdict))
+
+    def test_strdict(self):
+        class A:
+            a = 1
+            b = 2
+        assert self.is_strdict(A)

Modified: pypy/trunk/pypy/objspace/std/dictmultiobject.py
==============================================================================
--- pypy/trunk/pypy/objspace/std/dictmultiobject.py	(original)
+++ pypy/trunk/pypy/objspace/std/dictmultiobject.py	Tue Jan 26 18:45:48 2010
@@ -32,7 +32,7 @@
     @staticmethod
     def allocate_and_init_instance(space, w_type=None, module=False,
                                    instance=False, classofinstance=None,
-                                   from_strdict_shared=None):
+                                   from_strdict_shared=None, strdict=False):
         if from_strdict_shared is not None:
             assert w_type is None
             assert not module and not instance and classofinstance is None
@@ -57,7 +57,7 @@
                 classofinstance is not None):
             assert w_type is None
             return ShadowDetectingDictImplementation(space, classofinstance)
-        elif instance:
+        elif instance or strdict:
             assert w_type is None
             return StrDictImplementation(space)
         else:

Modified: pypy/trunk/pypy/objspace/std/objspace.py
==============================================================================
--- pypy/trunk/pypy/objspace/std/objspace.py	(original)
+++ pypy/trunk/pypy/objspace/std/objspace.py	Tue Jan 26 18:45:48 2010
@@ -506,12 +506,13 @@
         return W_ListObject(list_w)
 
     def newdict(self, module=False, instance=False, classofinstance=None,
-                from_strdict_shared=None):
+                from_strdict_shared=None, strdict=False):
         from pypy.objspace.std.dictmultiobject import W_DictMultiObject
         return W_DictMultiObject.allocate_and_init_instance(
                 self, module=module, instance=instance,
                 classofinstance=classofinstance,
-                from_strdict_shared=from_strdict_shared)
+                from_strdict_shared=from_strdict_shared,
+                strdict=strdict)
 
     def newslice(self, w_start, w_end, w_step):
         return W_SliceObject(w_start, w_end, w_step)



More information about the Pypy-commit mailing list