[pypy-svn] r76777 - in pypy/branch/better-map-instances/pypy: interpreter objspace/std objspace/std/test
cfbolz at codespeak.net
cfbolz at codespeak.net
Sun Aug 29 09:42:40 CEST 2010
Author: cfbolz
Date: Sun Aug 29 09:42:36 2010
New Revision: 76777
Modified:
pypy/branch/better-map-instances/pypy/interpreter/baseobjspace.py
pypy/branch/better-map-instances/pypy/interpreter/typedef.py
pypy/branch/better-map-instances/pypy/objspace/std/mapdict.py
pypy/branch/better-map-instances/pypy/objspace/std/test/test_mapdict.py
Log:
only use the slot index in mapdict, makes it possible to revert 76692 and kill
an XXX
Modified: pypy/branch/better-map-instances/pypy/interpreter/baseobjspace.py
==============================================================================
--- pypy/branch/better-map-instances/pypy/interpreter/baseobjspace.py (original)
+++ pypy/branch/better-map-instances/pypy/interpreter/baseobjspace.py Sun Aug 29 09:42:36 2010
@@ -105,10 +105,10 @@
return space.wrap("<%s at 0x%s%s>" % (info, addrstring,
moreinfo))
- def getslotvalue(self, member):
+ def getslotvalue(self, index):
raise NotImplementedError
- def setslotvalue(self, member, w_val):
+ def setslotvalue(self, index, w_val):
raise NotImplementedError
def descr_call_mismatch(self, space, opname, RequiredClass, args):
Modified: pypy/branch/better-map-instances/pypy/interpreter/typedef.py
==============================================================================
--- pypy/branch/better-map-instances/pypy/interpreter/typedef.py (original)
+++ pypy/branch/better-map-instances/pypy/interpreter/typedef.py Sun Aug 29 09:42:36 2010
@@ -255,10 +255,10 @@
def user_setup_slots(self, nslots):
if nslots > 0:
self.slots_w = [None] * nslots
- def setslotvalue(self, member, w_value):
- self.slots_w[member.index] = w_value
- def getslotvalue(self, member):
- return self.slots_w[member.index]
+ def setslotvalue(self, index, w_value):
+ self.slots_w[index] = w_value
+ def getslotvalue(self, index):
+ return self.slots_w[index]
add(Proto)
wantdict = "dict" in features
@@ -537,7 +537,7 @@
else:
self = member
self.typecheck(space, w_obj)
- w_result = w_obj.getslotvalue(self)
+ w_result = w_obj.getslotvalue(self.index)
if w_result is None:
raise OperationError(space.w_AttributeError,
space.wrap(self.name)) # XXX better message
@@ -548,14 +548,14 @@
Write into the slot 'member' of the given 'obj'."""
self = member
self.typecheck(space, w_obj)
- w_obj.setslotvalue(self, w_value)
+ w_obj.setslotvalue(self.index, w_value)
def descr_member_del(space, member, w_obj):
"""member.__delete__(obj)
Delete the value of the slot 'member' from the given 'obj'."""
self = member
self.typecheck(space, w_obj)
- w_obj.setslotvalue(self, None)
+ w_obj.setslotvalue(self.index, None)
Member.typedef = TypeDef(
"member_descriptor",
Modified: pypy/branch/better-map-instances/pypy/objspace/std/mapdict.py
==============================================================================
--- pypy/branch/better-map-instances/pypy/objspace/std/mapdict.py (original)
+++ pypy/branch/better-map-instances/pypy/objspace/std/mapdict.py Sun Aug 29 09:42:36 2010
@@ -291,14 +291,12 @@
assert not self.typedef.hasdict
self._init_empty(w_subtype.terminator)
- def getslotvalue(self, member):
- # XXX we don't need member here, it's enough to have member.index
- # XXX and revert the change to the signature of getslotvalue(), maybe.
- key = (member.name, SLOTS_STARTING_FROM + member.index)
+ def getslotvalue(self, index):
+ key = ("slot", SLOTS_STARTING_FROM + index)
return self.map.read(self, key)
- def setslotvalue(self, member, w_value):
- key = (member.name, SLOTS_STARTING_FROM + member.index)
+ def setslotvalue(self, index, w_value):
+ key = ("slot", SLOTS_STARTING_FROM + index)
self.map.write(self, key, w_value)
# used by _weakref implemenation
Modified: pypy/branch/better-map-instances/pypy/objspace/std/test/test_mapdict.py
==============================================================================
--- pypy/branch/better-map-instances/pypy/objspace/std/test/test_mapdict.py (original)
+++ pypy/branch/better-map-instances/pypy/objspace/std/test/test_mapdict.py Sun Aug 29 09:42:36 2010
@@ -4,11 +4,6 @@
space = FakeSpace()
-class FakeMember(object):
- def __init__(self, name, index=0):
- self.name = name
- self.index = index
-
class Class(object):
def __init__(self, hasdict=True):
self.hasdict = True
@@ -162,9 +157,9 @@
def test_slots():
cls = Class()
obj = cls.instantiate()
- a = FakeMember("a")
- b = FakeMember("b")
- c = FakeMember("c")
+ a = 0
+ b = 1
+ c = 2
obj.setslotvalue(a, 50)
obj.setslotvalue(b, 60)
obj.setslotvalue(c, 70)
@@ -194,27 +189,13 @@
assert obj2.storage == [501, 601, 701, 51, 61, 71]
assert obj.map is obj2.map
-def test_slots_same_name():
- cls = Class()
- obj = cls.instantiate()
- a = FakeMember("a")
- b = FakeMember("a", 1)
- c = FakeMember("a", 2)
- obj.setslotvalue(a, 50)
- obj.setslotvalue(b, 60)
- obj.setslotvalue(c, 70)
- assert obj.getslotvalue(a) == 50
- assert obj.getslotvalue(b) == 60
- assert obj.getslotvalue(c) == 70
- assert obj.storage == [50, 60, 70]
-
def test_slots_no_dict():
cls = Class(hasdict=False)
obj = cls.instantiate()
- a = FakeMember("a")
- b = FakeMember("b")
- c = FakeMember("c")
+ a = 0
+ b = 1
+ c = 2
obj.setslotvalue(a, 50)
obj.setslotvalue(b, 60)
assert obj.getslotvalue(a) == 50
@@ -235,9 +216,9 @@
def test_materialize_r_dict():
cls = Class()
obj = cls.instantiate()
- a = FakeMember("a")
- b = FakeMember("b")
- c = FakeMember("c")
+ a = 0
+ b = 1
+ c = 2
obj.setslotvalue(a, 50)
obj.setslotvalue(b, 60)
obj.setslotvalue(c, 70)
@@ -305,9 +286,9 @@
def test_get_setdictvalue_after_devolve():
cls = Class()
obj = cls.instantiate()
- a = FakeMember("a")
- b = FakeMember("b")
- c = FakeMember("c")
+ a = 0
+ b = 1
+ c = 2
obj.setslotvalue(a, 50)
obj.setslotvalue(b, 60)
obj.setslotvalue(c, 70)
More information about the Pypy-commit
mailing list