[pypy-svn] r36444 - in pypy/dist/pypy: config interpreter objspace objspace/std/test

cfbolz at codespeak.net cfbolz at codespeak.net
Wed Jan 10 23:43:27 CET 2007


Author: cfbolz
Date: Wed Jan 10 23:43:26 2007
New Revision: 36444

Modified:
   pypy/dist/pypy/config/pypyoption.py
   pypy/dist/pypy/interpreter/baseobjspace.py
   pypy/dist/pypy/interpreter/typedef.py
   pypy/dist/pypy/objspace/descroperation.py
   pypy/dist/pypy/objspace/std/test/test_shadowtracking.py
Log:
(pedronis, cfbolz): this checkin makes pypy 10-20% faster (if you enable
withshadowtracking). hehe. we avoid the lookup in the instance if the attribute
is on the class and there is no shadowing.


Modified: pypy/dist/pypy/config/pypyoption.py
==============================================================================
--- pypy/dist/pypy/config/pypyoption.py	(original)
+++ pypy/dist/pypy/config/pypyoption.py	Wed Jan 10 23:43:26 2007
@@ -148,9 +148,9 @@
         BoolOption("withshadowtracking",
                    "track whether an instance attribute shadows a type"
                    " attribute",
-                   cmdline=None,
                    default=False,
-                   requires=[("objspace.std.withmultidict", True)]),
+                   requires=[("objspace.std.withmultidict", True),
+                             ("objspace.std.withtypeversion", True)]),
 
 
         BoolOption("optimized_int_add",

Modified: pypy/dist/pypy/interpreter/baseobjspace.py
==============================================================================
--- pypy/dist/pypy/interpreter/baseobjspace.py	(original)
+++ pypy/dist/pypy/interpreter/baseobjspace.py	Wed Jan 10 23:43:26 2007
@@ -27,6 +27,9 @@
             return space.finditem(w_dict, w_attr)
         return None
 
+    def getdictvalue_attr_is_in_class(self, space, w_attr):
+        return self.getdictvalue(space, w_attr)
+
     def setdictvalue(self, space, w_attr, w_value, shadows_type=True):
         w_dict = self.getdict()
         if w_dict is not None:

Modified: pypy/dist/pypy/interpreter/typedef.py
==============================================================================
--- pypy/dist/pypy/interpreter/typedef.py	(original)
+++ pypy/dist/pypy/interpreter/typedef.py	Wed Jan 10 23:43:26 2007
@@ -178,6 +178,9 @@
                 if not space.is_true(space.isinstance(w_dict, space.w_dict)):
                     raise OperationError(space.w_TypeError,
                             space.wrap("setting dictionary to a non-dict"))
+                if space.config.objspace.std.withmultidict:
+                    from pypy.objspace.std import dictmultiobject
+                    assert isinstance(w_dict, dictmultiobject.W_DictMultiObject)
                 self.w__dict__ = w_dict
             
             def user_setup(self, space, w_subtype):
@@ -203,6 +206,13 @@
                 if space.config.objspace.std.withshadowtracking:
                     self.w__dict__.implementation.shadows_anything = True
 
+            def getdictvalue_attr_is_in_class(self, space, w_name):
+                w_dict = self.w__dict__
+                if space.config.objspace.std.withshadowtracking:
+                    if (not w_dict.implementation.shadows_anything and
+                        self.w__class__.version_tag is not None):
+                        return None
+                return space.finditem(w_dict, w_name)
             
     else:
         supercls = cls
@@ -213,6 +223,7 @@
                 return self.w__class__
             
             def setclass(self, space, w_subtype):
+
                 # only used by descr_set___class__
                 self.w__class__ = w_subtype
             

Modified: pypy/dist/pypy/objspace/descroperation.py
==============================================================================
--- pypy/dist/pypy/objspace/descroperation.py	(original)
+++ pypy/dist/pypy/objspace/descroperation.py	Wed Jan 10 23:43:26 2007
@@ -21,7 +21,9 @@
         if w_descr is not None:
             if space.is_data_descr(w_descr):
                 return space.get(w_descr, w_obj)
-        w_value = w_obj.getdictvalue(space, w_name)
+            w_value = w_obj.getdictvalue_attr_is_in_class(space, w_name)
+        else:
+            w_value = w_obj.getdictvalue(space, w_name)
         if w_value is not None:
             return w_value
         if w_descr is not None:

Modified: pypy/dist/pypy/objspace/std/test/test_shadowtracking.py
==============================================================================
--- pypy/dist/pypy/objspace/std/test/test_shadowtracking.py	(original)
+++ pypy/dist/pypy/objspace/std/test/test_shadowtracking.py	Wed Jan 10 23:43:26 2007
@@ -75,3 +75,12 @@
         """)
         assert w_inst.w__dict__.implementation.shadows_anything
 
+class AppTestShadowTracking(object):
+    def test_shadowtracking_does_not_blow_up(self):
+        class A(object):
+            def f(self):
+                return 42
+        a = A()
+        assert a.f() == 42
+        a.f = lambda : 43
+        assert a.f() == 43



More information about the Pypy-commit mailing list