[pypy-commit] pypy default: a bit of cleanup, remove some copies
cfbolz
pypy.commits at gmail.com
Sun Aug 20 06:55:23 EDT 2017
Author: Carl Friedrich Bolz <cfbolz at gmx.de>
Branch:
Changeset: r92179:190bc6072d6d
Date: 2017-08-20 12:54 +0200
http://bitbucket.org/pypy/pypy/changeset/190bc6072d6d/
Log: a bit of cleanup, remove some copies
diff --git a/pypy/module/cpyext/sequence.py b/pypy/module/cpyext/sequence.py
--- a/pypy/module/cpyext/sequence.py
+++ b/pypy/module/cpyext/sequence.py
@@ -294,6 +294,23 @@
def getitems_fixedsize(self, w_list):
return self.getitems_unroll(w_list)
+ def copy_into(self, w_list, w_other):
+ w_other.strategy = self
+ w_other.lstorage = self.getstorage_copy(w_list)
+
+ def clone(self, w_list):
+ storage = self.getstorage_copy(w_list)
+ w_clone = W_ListObject.from_storage_and_strategy(self.space, storage,
+ self)
+ return w_clone
+
+ def getitems_copy(self, w_list):
+ return self.getitems(w_list) # getitems copies anyway
+
+ def getstorage_copy(self, w_list):
+ lst = self.getitems(w_list)
+ return self.erase(CPyListStorage(w_list.space, lst))
+
#------------------------------------------
# all these methods fail or switch strategy and then call ListObjectStrategy's method
@@ -301,23 +318,9 @@
w_list.switch_to_object_strategy()
w_list.strategy.setslice(w_list, start, stop, step, length)
- def get_sizehint(self):
- return -1
-
def init_from_list_w(self, w_list, list_w):
raise NotImplementedError
- def clone(self, w_list):
- storage = w_list.lstorage # lstorage is tuple, no need to clone
- w_clone = W_ListObject.from_storage_and_strategy(self.space, storage,
- self)
- w_clone.switch_to_object_strategy()
- return w_clone
-
- def copy_into(self, w_list, w_other):
- w_list.switch_to_object_strategy()
- w_list.strategy.copy_into(w_list, w_other)
-
def _resize_hint(self, w_list, hint):
pass
@@ -325,17 +328,6 @@
w_list.switch_to_object_strategy()
return w_list.strategy.find(w_list, w_item, start, stop)
- def getitems_copy(self, w_list):
- w_list.switch_to_object_strategy()
- return w_list.strategy.getitems_copy(w_list)
-
- def getstorage_copy(self, w_list):
- storage = self.unerase(w_list.lstorage)
- lst = [None] * storage._length
- for i in range(storage._length):
- lst[i] = from_ref(w_list.space, storage._elems[i])
- return self.erase(CPyListStorage(w_list.space, lst))
-
def append(self, w_list, w_item):
w_list.switch_to_object_strategy()
w_list.strategy.append(w_list, w_item)
More information about the pypy-commit
mailing list