Author: Carl Friedrich Bolz <[email protected]>
Branch: list-strategies
Changeset: r47681:0d901f9bf92b
Date: 2011-09-29 16:12 +0200
http://bitbucket.org/pypy/pypy/changeset/0d901f9bf92b/
Log: add an option to enable list-strategies (more specifically: to
disable it, because it is on by default).
diff --git a/pypy/config/pypyoption.py b/pypy/config/pypyoption.py
--- a/pypy/config/pypyoption.py
+++ b/pypy/config/pypyoption.py
@@ -280,6 +280,9 @@
"actually create the full list until the resulting "
"list is mutated",
default=False),
+ BoolOption("withliststrategies",
+ "enable optimized ways to store lists of primitives ",
+ default=True),
BoolOption("withtypeversion",
"version type objects when changing them",
diff --git a/pypy/doc/config/objspace.std.withliststrategies.txt
b/pypy/doc/config/objspace.std.withliststrategies.txt
new file mode 100644
--- /dev/null
+++ b/pypy/doc/config/objspace.std.withliststrategies.txt
@@ -0,0 +1,2 @@
+Enable list strategies: Use specialized representations for lists of primitive
+objects, such as ints.
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
@@ -62,7 +62,10 @@
def __init__(w_self, space, wrappeditems):
assert isinstance(wrappeditems, list)
w_self.space = space
- w_self.strategy = get_strategy_from_list_objects(space, wrappeditems)
+ if space.config.objspace.std.withliststrategies:
+ w_self.strategy = get_strategy_from_list_objects(space,
wrappeditems)
+ else:
+ w_self.strategy = space.fromcache(ObjectListStrategy)
w_self.init_from_list_w(wrappeditems)
@staticmethod
diff --git a/pypy/objspace/std/test/test_liststrategies.py
b/pypy/objspace/std/test/test_liststrategies.py
--- a/pypy/objspace/std/test/test_liststrategies.py
+++ b/pypy/objspace/std/test/test_liststrategies.py
@@ -1,6 +1,8 @@
from pypy.objspace.std.listobject import W_ListObject, EmptyListStrategy,
ObjectListStrategy, IntegerListStrategy, StringListStrategy, RangeListStrategy,
make_range_list
from pypy.objspace.std.test.test_listobject import TestW_ListObject
+from pypy.conftest import gettestobjspace
+
class TestW_ListStrategies(TestW_ListObject):
def test_check_strategy(self):
@@ -345,3 +347,15 @@
assert isinstance(l2.strategy, ObjectListStrategy)
l3 = W_ListObject(self.space, [self.space.wrap("eins"),
self.space.wrap(u"zwei")])
assert isinstance(l3.strategy, ObjectListStrategy)
+
+
+class TestW_ListStrategiesDisabled:
+ def setup_class(cls):
+ cls.space = gettestobjspace(**{"objspace.std.withliststrategies" :
+ False})
+
+ def test_check_strategy(self):
+ assert isinstance(W_ListObject(self.space, []).strategy,
ObjectListStrategy)
+ assert isinstance(W_ListObject(self.space,
[self.space.wrap(1),self.space.wrap('a')]).strategy, ObjectListStrategy)
+ assert isinstance(W_ListObject(self.space,
[self.space.wrap(1),self.space.wrap(2),self.space.wrap(3)]).strategy,
ObjectListStrategy)
+ assert isinstance(W_ListObject(self.space, [self.space.wrap('a'),
self.space.wrap('b')]).strategy, ObjectListStrategy)
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit