Commits

Armin Rigo committed c49198d

Performance improvement.

Comments (0)

Files changed (2)

pypy/objspace/std/listobject.py

         new erased object as storage"""
         self.strategy.init_from_list_w(self, list_w)
 
-    def clear(self):
-        """Make the listobject empty."""
-        if self.space.config.objspace.std.withliststrategies:
-            strategy = self.space.fromcache(EmptyListStrategy)
+    def clear(self, space):
+        """Initializes (or overrides) the listobject as empty."""
+        self.space = space
+        if space.config.objspace.std.withliststrategies:
+            strategy = space.fromcache(EmptyListStrategy)
         else:
-            strategy = self.space.fromcache(ObjectListStrategy)
+            strategy = space.fromcache(ObjectListStrategy)
         self.strategy = strategy
         strategy.clear(self)
 
     # this is on the silly side
     w_iterable, = __args__.parse_obj(
             None, 'list', init_signature, init_defaults)
-    w_list.clear()
+    w_list.clear(space)
     if w_iterable is not None:
         if isinstance(w_iterable, W_ListObject):
             w_iterable.copy_into(w_list)

pypy/objspace/std/listtype.py

 def descr__new__(space, w_listtype, __args__):
     from pypy.objspace.std.listobject import W_ListObject
     w_obj = space.allocate_instance(W_ListObject, w_listtype)
-    W_ListObject.__init__(w_obj, space, [])
+    w_obj.clear(space)
     return w_obj
 
 # ____________________________________________________________