[pypy-commit] pypy SpecialisedTuples: (antocuni, mwp) not interested in 1-tuples really, kill the code
mwp
noreply at buildbot.pypy.org
Thu Nov 10 10:47:21 CET 2011
Author: Mark Pearse <mark.pearse at skynet.be>
Branch: SpecialisedTuples
Changeset: r49078:584b7dda8f49
Date: 2011-11-04 16:59 +0100
http://bitbucket.org/pypy/pypy/changeset/584b7dda8f49/
Log: (antocuni, mwp) not interested in 1-tuples really, kill the code
diff --git a/pypy/objspace/std/specialisedtupleobject.py b/pypy/objspace/std/specialisedtupleobject.py
--- a/pypy/objspace/std/specialisedtupleobject.py
+++ b/pypy/objspace/std/specialisedtupleobject.py
@@ -39,42 +39,23 @@
def unwrap(w_tuple, space):
return tuple(self.tolist)
-class W_SpecialisedTupleObject1(W_SpecialisedTupleObject): #one element tuples
- def __init__(self, value0):
- raise NotImplementedError
+
+class W_SpecialisedTupleObjectIntInt(W_SpecialisedTupleObject):
+ def __init__(self, intval0, intval1):
+ assert isinstance(intval0, int)
+ assert isinstance(intval1, int)
+ self.intval0 = intval0
+ self.intval1 = intval1
def length(self):
- return 1
-
- def eq(self, space, w_other):
- if w_other.length() != 1:
- return space.w_False
- if self.value0 == w_other.value0: #is it safe to assume all 1-tuples are specialised ?
- return space.w_True
- else:
- return space.w_False
-
- def hash(self, space):
- mult = 1000003
- x = 0x345678
- z = 1
- w_item = self.getitem(0)
- y = space.int_w(space.hash(w_item))
- x = (x ^ y) * mult
- mult += 82520 + z + z
- x += 97531
- return space.wrap(intmask(x))
-
-class W_SpecialisedTupleObjectInt(W_SpecialisedTupleObject1): #one integer element
- def __init__(self, intval):
- assert type(intval) == IntType#isinstance
- self.intval = intval#intval
-
+ return 2
+'''
def tolist(self):
return [W_IntObject(self.intval)]
def getitem(self, index):
if index == 0:
+ self.wrap(self.intval)
return W_IntObject(self.intval)
raise IndexError
@@ -85,61 +66,17 @@
return
raise IndexError
-class W_SpecialisedTupleObjectFloat(W_SpecialisedTupleObject1): #one integer element
- def __init__(self, floatval):
- assert type(floatval) == FloatType
- self.floatval = floatval
+ def eq(self, space, w_other):
+ if w_other.length() != 1:
+ return space.w_False
+ if self.intval == w_other.intval: #is it safe to assume all 1-tuples are specialised ?
+ return space.w_True
+ else:
+ return space.w_False
+'''
- def tolist(self):
- return [W_FloatObject(self.floatval)]
-
- def getitem(self, index):
- if index == 0:
- return W_FloatObject(self.floatval)
- raise IndexError
-
- def setitem(self, index, w_item):
- assert isinstance(w_item, W_FloatObject)
- if index == 0:
- self.floatval = w_item.floatval
- return
- raise IndexError
-
-class W_SpecialisedTupleObjectString(W_SpecialisedTupleObject1): #one integer element
- def __init__(self, stringval):
- assert type(stringval) == StringType
- self.stringval = stringval
-
- def tolist(self):
- return [W_StringObject(self.stringval)]
-
- def getitem(self, index):
- if index == 0:
- return W_StringObject(self.stringval)
- raise IndexError
-
- def setitem(self, index, w_item):
- assert isinstance(w_item, W_StringObject)
- if index == 0:
- self.stringval = w_item._value # does _value need to be private
- return
- raise IndexError
-
-'''
- W_SpecialisedTupleObjectIntInt, #two element tupes of int, float or string
- W_SpecialisedTupleObjectIntFloat,
- W_SpecialisedTupleObjectIntString,
- W_SpecialisedTupleObjectFloatInt,
- W_SpecialisedTupleObjectFloatFloat,
- W_SpecialisedTupleObjectFloatString,
- W_SpecialisedTupleObjectStringInt,
- W_SpecialisedTupleObjectStringFloat,
- W_SpecialisedTupleObjectStringString
-
-'''
registerimplementation(W_SpecialisedTupleObject)
-#---------
def delegate_SpecialisedTuple2Tuple(space, w_specialised):
return W_TupleObject(w_specialised.tolist())
@@ -156,8 +93,6 @@
raise OperationError(space.w_IndexError,
space.wrap("tuple index out of range"))
-# getitem__SpecialisedTuple_Slice removed
-# mul_specialisedtuple_times removed
def getitem__SpecialisedTuple_Slice(space, w_tuple, w_slice):
length = w_tuple.length()
start, stop, step, slicelength = w_slice.indices4(space, length)
@@ -186,10 +121,6 @@
def mul__ANY_SpecialisedTuple(space, w_times, w_tuple):
return mul_specialisedtuple_times(space, w_tuple, w_times)
-
-# mul__SpecialisedTuple_ANY removed
-# mul__ANY_SpecialisedTuple removed
-
def eq__SpecialisedTuple_SpecialisedTuple(space, w_tuple1, w_tuple2):
return w_tuple1.eq(space, w_tuple2)
diff --git a/pypy/objspace/std/test/test_specialisedtupleobject.py b/pypy/objspace/std/test/test_specialisedtupleobject.py
--- a/pypy/objspace/std/test/test_specialisedtupleobject.py
+++ b/pypy/objspace/std/test/test_specialisedtupleobject.py
@@ -1,28 +1,28 @@
+import py
from pypy.objspace.std.tupleobject import W_TupleObject
-from pypy.objspace.std.specialisedtupleobject import W_SpecialisedTupleObject
+from pypy.objspace.std.specialisedtupleobject import W_SpecialisedTupleObject,W_SpecialisedTupleObjectIntInt
from pypy.interpreter.error import OperationError
from pypy.conftest import gettestobjspace
from pypy.objspace.std.test.test_tupleobject import AppTestW_TupleObject
+
class TestW_SpecialisedTupleObject():
def setup_class(cls):
cls.space = gettestobjspace(**{"objspace.std.withspecialisedtuple": True})
- def test_isspecialisedtupleobject(self):
- w_tuple = self.space.newtuple([self.space.wrap(1)])
- assert isinstance(w_tuple, W_SpecialisedTupleObject)
-
+ def test_isspecialisedtupleobjectintint(self):
+ py.test.skip('in progress')
+ w_tuple = self.space.newtuple([self.space.wrap(1), self.space.wrap(2)])
+ assert isinstance(w_tuple, W_SpecialisedTupleObjectIntInt)
+
def test_isnotspecialisedtupleobject(self):
w_tuple = self.space.newtuple([self.space.wrap({})])
assert not isinstance(w_tuple, W_SpecialisedTupleObject)
-
- def test_isnotspecialised2tupleobject(self):
- w_tuple = self.space.newtuple([self.space.wrap(1), self.space.wrap(2)])
- assert not isinstance(w_tuple, W_SpecialisedTupleObject)
def test_hash_against_normal_tuple(self):
+ py.test.skip('in progress')
normalspace = gettestobjspace(**{"objspace.std.withspecialisedtuple": False})
w_tuple = normalspace.newtuple([self.space.wrap(1)])
@@ -36,6 +36,7 @@
assert specialisedspace.is_true(specialisedspace.eq(normalspace.hash(w_tuple), specialisedspace.hash(w_specialisedtuple)))
def test_setitem(self):
+ py.test.skip('in progress')
w_specialisedtuple = self.space.newtuple([self.space.wrap(1)])
w_specialisedtuple.setitem(0, self.space.wrap(5))
list_w = w_specialisedtuple.tolist()
@@ -54,48 +55,43 @@
""")
def test_specialisedtuple(self):
- assert self.isspecialised((42,))
- assert self.isspecialised(('42',))
- assert self.isspecialised((42.5,))
-
+ skip('in progress')
+ assert self.isspecialised((42,43))
+
def test_notspecialisedtuple(self):
- assert not self.isspecialised((42,43))
+ skip('in progress')
+ assert not self.isspecialised((42,43,44))
def test_slicing_to_specialised(self):
+ skip('in progress')
assert self.isspecialised((1, 2, 3)[0:1])
assert self.isspecialised((1, '2', 1.3)[0:5:5])
assert self.isspecialised((1, '2', 1.3)[1:5:5])
assert self.isspecialised((1, '2', 1.3)[2:5:5])
def test_adding_to_specialised(self):
- assert self.isspecialised(()+(2,))
+ skip('in progress')
+ assert self.isspecialised((1,)+(2,))
def test_multiply_to_specialised(self):
- assert self.isspecialised((1,)*1)
+ skip('in progress')
+ assert self.isspecialised((1,)*2)
def test_slicing_from_specialised(self):
- assert (1,)[0:1:1] == (1,)
+ skip('in progress')
+ assert (1,2,3)[0:2:1] == (1,)
def test_eq(self):
- a = (1,)
- b = (1,)
- assert a == b
-
- a = ('1',)
- b = ('1',)
- assert a == b
-
- a = (1.1,)
- b = (1.1,)
+ skip('in progress')
+ a = (1,2)
+ b = (1,2)
assert a == b
c = (1,3,2)
assert a != c
-
- d = (2)
- assert a != d
def test_hash(self):
+ skip('in progress')
a = (1,)
b = (1,)
assert hash(a) == hash(b)
diff --git a/pypy/objspace/std/tupletype.py b/pypy/objspace/std/tupletype.py
--- a/pypy/objspace/std/tupletype.py
+++ b/pypy/objspace/std/tupletype.py
@@ -15,22 +15,12 @@
from pypy.objspace.std.smalltupleobject import W_SmallTupleObject7
from pypy.objspace.std.smalltupleobject import W_SmallTupleObject8
- from pypy.objspace.std.specialisedtupleobject import W_SpecialisedTupleObjectInt #one element tuples
- from pypy.objspace.std.specialisedtupleobject import W_SpecialisedTupleObjectFloat
- from pypy.objspace.std.specialisedtupleobject import W_SpecialisedTupleObjectString
from pypy.objspace.std.intobject import W_IntObject
from pypy.objspace.std.floatobject import W_FloatObject
from pypy.objspace.std.stringobject import W_StringObject
if space.config.objspace.std.withspecialisedtuple:
- if len(list_w) == 1:
- if isinstance(list_w[0], W_IntObject):
- return W_SpecialisedTupleObjectInt(list_w[0].intval)
- if isinstance(list_w[0], W_FloatObject):
- return W_SpecialisedTupleObjectFloat(list_w[0].floatval)
- if isinstance(list_w[0], W_StringObject):
- return W_SpecialisedTupleObjectString(list_w[0]._value)
-
+ pass
if space.config.objspace.std.withsmalltuple:
if len(list_w) == 2:
return W_SmallTupleObject2(list_w)
More information about the pypy-commit
mailing list