Author: Armin Rigo <[email protected]>
Branch: 
Changeset: r58653:66ca6d9f3739
Date: 2012-10-31 18:09 +0100
http://bitbucket.org/pypy/pypy/changeset/66ca6d9f3739/

Log:    Tweak tweak. Unclear if this gives enough win any more to care...

diff --git a/pypy/objspace/std/test/test_typeobject.py 
b/pypy/objspace/std/test/test_typeobject.py
--- a/pypy/objspace/std/test/test_typeobject.py
+++ b/pypy/objspace/std/test/test_typeobject.py
@@ -1175,9 +1175,9 @@
 """)
         w_A, w_B, w_M = space.unpackiterable(w_tup)
 
-        assert w_A.w_bltin_new is None
-        assert w_B.w_bltin_new is None
-        assert w_M.w_bltin_new is None                
+        assert w_A.w_new_function is None
+        assert w_B.w_new_function is None
+        assert w_M.w_new_function is None                
 
         _, w_object_newdescr = space.lookup_in_type_where(space.w_object,
                                                           '__new__')
@@ -1185,17 +1185,18 @@
                                      w_type=space.w_object)
 
         w_a = space.call_function(w_A)
-        assert w_A.w_bltin_new is w_object___new__
+        assert w_A.w_new_function is w_object___new__
 
         # will shortcut
         w_a = space.call_function(w_A)
 
         w_b = space.call_function(w_B)
-        assert w_B.w_bltin_new is None
+        assert w_B.w_new_function is not None
+        w_b = space.call_function(w_B)
 
         w_m = space.call_function(w_M, space.wrap('C'), space.newlist([]),
                                   space.newdict())
-        assert w_M.w_bltin_new is None                                  
+        assert w_M.w_new_function is not None
 
 
 class AppTestNewShortcut:
diff --git a/pypy/objspace/std/typeobject.py b/pypy/objspace/std/typeobject.py
--- a/pypy/objspace/std/typeobject.py
+++ b/pypy/objspace/std/typeobject.py
@@ -113,10 +113,8 @@
     # for config.objspace.std.withidentitydict
     compares_by_identity_status = UNKNOWN
 
-    # used to cache the type __new__ function if it comes from a builtin type
-    # != 'type', in that case call__Type will also assumes the result
-    # of the __new__ is an instance of the type
-    w_bltin_new = None
+    # used to cache the type's __new__ function
+    w_new_function = None
 
     @dont_look_inside
     def __init__(w_self, space, name, bases_w, dict_w,
@@ -181,7 +179,7 @@
                 w_self.compares_by_identity_status = UNKNOWN
 
         if space.config.objspace.std.newshortcut:
-            w_self.w_bltin_new = None
+            w_self.w_new_function = None
 
         if (space.config.objspace.std.withtypeversion
             and w_self._version_tag is not None):
@@ -824,32 +822,23 @@
     promote(w_type)
     # invoke the __new__ of the type
     if not we_are_jitted():
-        # note that the annotator will figure out that w_type.w_bltin_new can
-        # only be None if the newshortcut config option is not set
-        w_bltin_new = w_type.w_bltin_new
+        # note that the annotator will figure out that w_type.w_new_function
+        # can only be None if the newshortcut config option is not set
+        w_newfunc = w_type.w_new_function
     else:
         # for the JIT it is better to take the slow path because normal lookup
-        # is nicely optimized, but the w_type.w_bltin_new attribute is not
+        # is nicely optimized, but the w_type.w_new_function attribute is not
         # known to the JIT
-        w_bltin_new = None
-    call_init = True
-    if w_bltin_new is not None:
-        w_newobject = space.call_obj_args(w_bltin_new, w_type, __args__)
-    else:
+        w_newfunc = None
+    if w_newfunc is None:
         w_newtype, w_newdescr = w_type.lookup_where('__new__')
         w_newfunc = space.get(w_newdescr, w_type)
         if (space.config.objspace.std.newshortcut and
             not we_are_jitted() and
-            isinstance(w_newtype, W_TypeObject) and
-            not w_newtype.is_heaptype() and
-            not space.is_w(w_newtype, space.w_type)):
-            w_type.w_bltin_new = w_bltin_new = w_newfunc
-        w_newobject = space.call_obj_args(w_newfunc, w_type, __args__)
-        call_init = space.isinstance_w(w_newobject, w_type)
-
-    # sanity check
-    if not we_are_translated() and w_bltin_new is not None:
-        assert space.isinstance_w(w_newobject, w_type)
+            isinstance(w_newtype, W_TypeObject)):
+            w_type.w_new_function = w_newfunc
+    w_newobject = space.call_obj_args(w_newfunc, w_type, __args__)
+    call_init = space.isinstance_w(w_newobject, w_type)
 
     # maybe invoke the __init__ of the type
     if (call_init and not (space.is_w(w_type, space.w_type) and
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to