Author: Lukas Diekmann <[email protected]>
Branch: list-strategies
Changeset: r47481:4fc5434c0449
Date: 2011-03-22 11:23 +0100
http://bitbucket.org/pypy/pypy/changeset/4fc5434c0449/
Log: added new method copy_into to extend an EmptyList with other lists
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
@@ -86,6 +86,8 @@
self.strategy = self.space.fromcache(EmptyListStrategy)
self.strategy.init_from_list_w(self, [])
+ def copy_into(self, other):
+ self.strategy.copy_into(self, other)
# ___________________________________________________
def append(w_list, w_item):
@@ -233,9 +235,7 @@
self.append(w_list, w_item)
def extend(self, w_list, w_other):
- strategy = w_list.strategy = w_other.strategy
- items = strategy.cast_from_void_star(w_other.lstorage)[:] # copy!
- w_list.lstorage = strategy.cast_to_void_star(items)
+ w_other.copy_into(w_list)
def reverse(self, w_list):
pass
@@ -260,6 +260,10 @@
cast_to_void_star = staticmethod(cast_to_void_star)
cast_from_void_star = staticmethod(cast_from_void_star)
+ def copy_into(self, w_list, w_other):
+ w_other.strategy = self
+ w_other.lstorage = w_list.lstorage
+
def length(self, w_list):
return self.cast_from_void_star(w_list.lstorage)[2]
@@ -408,6 +412,11 @@
l = [self.unwrap(w_item) for w_item in list_w]
w_list.lstorage = self.cast_to_void_star(l)
+ def copy_into(self, w_list, w_other):
+ w_other.strategy = self
+ items = self.cast_from_void_star(w_list.lstorage)[:]
+ w_other.lstorage = self.cast_to_void_star(items)
+
def length(self, w_list):
return len(self.cast_from_void_star(w_list.lstorage))
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit