[pypy-commit] pypy remove-tuple-smm: Remove smalltuples. They are disabled by default and can easily be readded.
Manuel Jacob
noreply at buildbot.pypy.org
Wed May 22 14:39:57 CEST 2013
Author: Manuel Jacob
Branch: remove-tuple-smm
Changeset: r64447:9ff8b4beff41
Date: 2013-05-22 14:37 +0200
http://bitbucket.org/pypy/pypy/changeset/9ff8b4beff41/
Log: Remove smalltuples. They are disabled by default and can easily be
readded.
diff --git a/pypy/config/pypyoption.py b/pypy/config/pypyoption.py
--- a/pypy/config/pypyoption.py
+++ b/pypy/config/pypyoption.py
@@ -215,10 +215,6 @@
"(the empty string and potentially single-char strings)",
default=False),
- BoolOption("withsmalltuple",
- "use small tuples",
- default=False),
-
BoolOption("withspecialisedtuple",
"use specialised tuples",
default=False),
diff --git a/pypy/objspace/std/smalltupleobject.py b/pypy/objspace/std/smalltupleobject.py
deleted file mode 100644
--- a/pypy/objspace/std/smalltupleobject.py
+++ /dev/null
@@ -1,75 +0,0 @@
-from pypy.interpreter.error import OperationError
-from pypy.objspace.std.tupleobject import W_AbstractTupleObject
-from pypy.objspace.std.util import negate
-from rpython.rlib.rarithmetic import intmask
-from rpython.rlib.unroll import unrolling_iterable
-from rpython.tool.sourcetools import func_with_new_name
-
-
-def make_specialized_class(n):
- iter_n = unrolling_iterable(range(n))
-
- class cls(W_AbstractTupleObject):
- def __init__(self, values):
- assert len(values) == n
- for i in iter_n:
- setattr(self, 'w_value%s' % i, values[i])
-
- def tolist(self):
- l = [None] * n
- for i in iter_n:
- l[i] = getattr(self, 'w_value%s' % i)
- return l
-
- # same source code, but builds and returns a resizable list
- getitems_copy = func_with_new_name(tolist, 'getitems_copy')
-
- def length(self):
- return n
-
- def getitem(self, space, index):
- if index < 0:
- index += n
- for i in iter_n:
- if index == i:
- return getattr(self, 'w_value%s' % i)
- raise OperationError(space.w_IndexError,
- space.wrap("tuple index out of range"))
-
- def descr_eq(self, space, w_other):
- if not isinstance(w_other, W_AbstractTupleObject):
- return space.w_NotImplemented
- if n != w_other.length():
- return space.w_False
- for i in iter_n:
- item1 = getattr(self, 'w_value%s' % i)
- item2 = w_other.getitem(space, i)
- if not space.eq_w(item1, item2):
- return space.w_False
- return space.w_True
-
- descr_ne = negate(descr_eq)
-
- def descr_hash(self, space):
- mult = 1000003
- x = 0x345678
- z = n
- for i in iter_n:
- w_item = getattr(self, 'w_value%s' % i)
- y = space.int_w(space.hash(w_item))
- x = (x ^ y) * mult
- z -= 1
- mult += 82520 + z + z
- x += 97531
- return space.wrap(intmask(x))
-
- cls.__name__ = "W_SmallTupleObject%s" % n
- return cls
-
-W_SmallTupleObject2 = make_specialized_class(2)
-W_SmallTupleObject3 = make_specialized_class(3)
-W_SmallTupleObject4 = make_specialized_class(4)
-W_SmallTupleObject5 = make_specialized_class(5)
-W_SmallTupleObject6 = make_specialized_class(6)
-W_SmallTupleObject7 = make_specialized_class(7)
-W_SmallTupleObject8 = make_specialized_class(8)
diff --git a/pypy/objspace/std/test/test_smalltupleobject.py b/pypy/objspace/std/test/test_smalltupleobject.py
deleted file mode 100644
--- a/pypy/objspace/std/test/test_smalltupleobject.py
+++ /dev/null
@@ -1,77 +0,0 @@
-from pypy.objspace.std.smalltupleobject import W_SmallTupleObject2
-from pypy.objspace.std.test.test_tupleobject import AppTestW_TupleObject
-from pypy.objspace.std.tupleobject import W_TupleObject
-
-
-class AppTestW_SmallTupleObject(AppTestW_TupleObject):
- spaceconfig = {"objspace.std.withsmalltuple": True}
-
- def setup_class(cls):
- cls.w_issmall = cls.space.appexec([], """():
- import __pypy__
- def issmall(obj):
- assert "SmallTuple" in __pypy__.internal_repr(obj)
- return issmall
- """)
-
- def test_smalltuple(self):
- self.issmall((1, 2))
- self.issmall((1, 2, 3))
-
- def test_slicing_to_small(self):
- self.issmall((1, 2, 3)[0:2]) # SmallTuple2
- self.issmall((1, 2, 3)[0:2:1])
-
- self.issmall((1, 2, 3, 4)[0:3]) # SmallTuple3
- self.issmall((1, 2, 3, 4)[0:3:1])
-
- def test_adding_to_small(self):
- self.issmall((1,) + (2,)) # SmallTuple2
- self.issmall((1, 1) + (2,)) # SmallTuple3
- self.issmall((1,) + (2, 3))
-
- def test_multiply_to_small(self):
- self.issmall((1,) * 2)
- self.issmall((1,) * 3)
-
- def test_slicing_from_small(self):
- assert (1, 2)[0:1:1] == (1,)
- assert (1, 2, 3)[0:2:1] == (1, 2)
-
- def test_eq(self):
- a = (1, 2, 3)
- b = (1, 2, 3)
- assert a == b
-
- c = (1, 3, 2)
- assert a != c
-
- def test_hash(self):
- a = (1, 2, 3)
- b = (1, 2, 3)
- assert hash(a) == hash(b)
-
- c = (1, 3, 2)
- assert hash(a) != hash(c)
-
- def test_foo(self):
- assert tuple([0]) + (1,) == (0, 1)
- assert not tuple([0]) + (1,) == (0,)
-
-
-class TestW_SmallTupleObject():
- spaceconfig = {"objspace.std.withsmalltuple": True}
-
- def test_issmalltupleobject(self):
- w_tuple = self.space.newtuple([self.space.wrap(1), self.space.wrap(2)])
- assert isinstance(w_tuple, W_SmallTupleObject2)
-
- def test_hash_agains_normal_tuple(self):
- w_tuple = W_TupleObject([self.space.wrap(1), self.space.wrap(2)])
- w_smalltuple = self.space.newtuple([self.space.wrap(1),
- self.space.wrap(2)])
- assert isinstance(w_smalltuple, W_SmallTupleObject2)
-
- assert self.space.is_true(self.space.eq(w_tuple, w_smalltuple))
- assert self.space.is_true(self.space.eq(self.space.hash(w_tuple),
- self.space.hash(w_smalltuple)))
diff --git a/pypy/objspace/std/tupleobject.py b/pypy/objspace/std/tupleobject.py
--- a/pypy/objspace/std/tupleobject.py
+++ b/pypy/objspace/std/tupleobject.py
@@ -292,27 +292,4 @@
return makespecialisedtuple(space, list_w)
except NotSpecialised:
pass
-
- if space.config.objspace.std.withsmalltuple:
- from pypy.objspace.std.smalltupleobject import W_SmallTupleObject2
- from pypy.objspace.std.smalltupleobject import W_SmallTupleObject3
- from pypy.objspace.std.smalltupleobject import W_SmallTupleObject4
- from pypy.objspace.std.smalltupleobject import W_SmallTupleObject5
- from pypy.objspace.std.smalltupleobject import W_SmallTupleObject6
- from pypy.objspace.std.smalltupleobject import W_SmallTupleObject7
- from pypy.objspace.std.smalltupleobject import W_SmallTupleObject8
- if len(list_w) == 2:
- return W_SmallTupleObject2(list_w)
- if len(list_w) == 3:
- return W_SmallTupleObject3(list_w)
- if len(list_w) == 4:
- return W_SmallTupleObject4(list_w)
- if len(list_w) == 5:
- return W_SmallTupleObject5(list_w)
- if len(list_w) == 6:
- return W_SmallTupleObject6(list_w)
- if len(list_w) == 7:
- return W_SmallTupleObject7(list_w)
- if len(list_w) == 8:
- return W_SmallTupleObject8(list_w)
return W_TupleObject(list_w)
More information about the pypy-commit
mailing list