[pypy-commit] pypy list-strategies: (cfbolz, l.diekmann): one less copy in extend

l.diekmann noreply at buildbot.pypy.org
Fri Sep 23 13:12:56 CEST 2011


Author: Lukas Diekmann <lukas.diekmann at uni-duesseldorf.de>
Branch: list-strategies
Changeset: r47488:42ec7bd0633f
Date: 2011-03-29 11:41 +0200
http://bitbucket.org/pypy/pypy/changeset/42ec7bd0633f/

Log:	(cfbolz, l.diekmann): one less copy in extend

diff --git a/pypy/objspace/std/listobject.py b/pypy/objspace/std/listobject.py
--- a/pypy/objspace/std/listobject.py
+++ b/pypy/objspace/std/listobject.py
@@ -213,6 +213,7 @@
         return W_ListObject(self.space, [])
 
     def getitems(self, w_list):
+        # cache result XXX
         return []
 
     def append(self, w_list, w_item):
@@ -479,10 +480,12 @@
         elif w_other.strategy is self.space.fromcache(EmptyListStrategy):
             return
 
-        #XXX unnecessary copy if w_other is ObjectList
         list_w = w_other.getitems()
-        w_other = W_ListObject(self.space, list_w)
-        w_other.switch_to_object_strategy()
+        strategy = self.space.fromcache(ObjectListStrategy)
+        storage = strategy.cast_to_void_star(list_w)
+        # NB: w_other shares its storage with the original w_other.  the new
+        # w_other does not survive long, so this is not a problem
+        w_other = W_ListObject.from_storage_and_strategy(self.space, storage, strategy)
 
         w_list.switch_to_object_strategy()
         w_list.extend(w_other)


More information about the pypy-commit mailing list