[pypy-commit] pypy set-strategies: Fix test_listobject by moving 'w_list.__init__(space, [])' to the start
arigo
noreply at buildbot.pypy.org
Mon Mar 26 16:21:54 CEST 2012
Author: Armin Rigo <arigo at tunes.org>
Branch: set-strategies
Changeset: r53992:7127deeed841
Date: 2012-03-26 16:16 +0200
http://bitbucket.org/pypy/pypy/changeset/7127deeed841/
Log: Fix test_listobject by moving 'w_list.__init__(space, [])' to the
start of the function again, and optimizing it to 'w_list.clear()',
which does not perform any allocation if liststrategies are enabled.
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
@@ -139,6 +139,15 @@
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)
+ else:
+ strategy = self.space.fromcache(ObjectListStrategy)
+ self.strategy = strategy
+ strategy.clear(self)
+
def clone(self):
"""Returns a clone by creating a new listobject
with the same strategy and a copy of the storage"""
@@ -366,6 +375,9 @@
assert len(list_w) == 0
w_list.lstorage = self.erase(None)
+ def clear(self, w_list):
+ w_list.lstorage = self.erase(None)
+
erase, unerase = rerased.new_erasing_pair("empty")
erase = staticmethod(erase)
unerase = staticmethod(unerase)
@@ -949,6 +961,9 @@
def init_from_list_w(self, w_list, list_w):
w_list.lstorage = self.erase(list_w)
+ def clear(self, w_list):
+ w_list.lstorage = self.erase([])
+
def contains(self, w_list, w_obj):
return ListStrategy.contains(self, w_list, w_obj)
@@ -1052,6 +1067,7 @@
# this is on the silly side
w_iterable, = __args__.parse_obj(
None, 'list', init_signature, init_defaults)
+ w_list.clear()
if w_iterable is not None:
if isinstance(w_iterable, W_ListObject):
w_iterable.copy_into(w_list)
@@ -1074,7 +1090,6 @@
w_list.lstorage = strategy.erase(strlist[:])
return
- w_list.__init__(space, [])
# xxx special hack for speed
from pypy.interpreter.generator import GeneratorIterator
if isinstance(w_iterable, GeneratorIterator):
@@ -1082,8 +1097,6 @@
return
# /xxx
_init_from_iterable(space, w_list, w_iterable)
- else:
- w_list.__init__(space, [])
def _init_from_iterable(space, w_list, w_iterable):
# in its own function to make the JIT look into init__List
More information about the pypy-commit
mailing list