[pypy-svn] r76845 - in pypy/branch/better-map-instances/pypy/objspace/std: . test
arigo at codespeak.net
arigo at codespeak.net
Thu Sep 2 20:07:19 CEST 2010
Author: arigo
Date: Thu Sep 2 20:07:15 2010
New Revision: 76845
Modified:
pypy/branch/better-map-instances/pypy/objspace/std/mapdict.py
pypy/branch/better-map-instances/pypy/objspace/std/test/test_mapdict.py
pypy/branch/better-map-instances/pypy/objspace/std/typeobject.py
Log:
(cfbolz, arigo)
Speed up reading the class of an instance as a mapdict,
by duplicating this info on all PlainAttributes.
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 Thu Sep 2 20:07:15 2010
@@ -1,4 +1,4 @@
-from pypy.rlib import jit
+from pypy.rlib import jit, objectmodel
from pypy.interpreter.baseobjspace import W_Root
from pypy.objspace.std.dictmultiobject import W_DictMultiObject
@@ -14,6 +14,10 @@
cache_attrs = None
_size_estimate = 0
+ def __init__(self, space, w_cls):
+ self.space = space
+ self.w_cls = w_cls
+
def read(self, obj, selector):
raise NotImplementedError("abstract base class")
@@ -83,9 +87,6 @@
class Terminator(AbstractAttribute):
_immutable_fields_ = ['w_cls']
- def __init__(self, w_cls, space):
- self.w_cls = w_cls
- self.space = space
def read(self, obj, selector):
return None
@@ -117,9 +118,9 @@
class DictTerminator(Terminator):
_immutable_fields_ = ['devolved_dict_terminator']
- def __init__(self, w_cls, space):
- Terminator.__init__(self, w_cls, space)
- self.devolved_dict_terminator = DevolvedDictTerminator(w_cls, space)
+ def __init__(self, space, w_cls):
+ Terminator.__init__(self, space, w_cls)
+ self.devolved_dict_terminator = DevolvedDictTerminator(space, w_cls)
def materialize_r_dict(self, space, obj, w_d):
result = Object()
@@ -176,6 +177,7 @@
class PlainAttribute(AbstractAttribute):
_immutable_fields_ = ['selector', 'position', 'back']
def __init__(self, selector, back):
+ AbstractAttribute.__init__(self, back.space, back.w_cls)
self.selector = selector
self.position = back.length()
self.back = back
@@ -315,7 +317,7 @@
assert flag
def getclass(self, space):
- return self._get_mapdict_map().get_terminator().w_cls
+ return self._get_mapdict_map().w_cls
def setclass(self, space, w_cls):
new_obj = self._get_mapdict_map().set_terminator(self, w_cls.terminator)
@@ -464,7 +466,8 @@
failure_counter = 0
INVALID_CACHE_ENTRY = CacheEntry()
-INVALID_CACHE_ENTRY.map = AbstractAttribute() # different from any real map
+INVALID_CACHE_ENTRY.map = objectmodel.instantiate(AbstractAttribute)
+ # different from any real map ^^^
def init_mapdict_cache(pycode):
num_entries = len(pycode.co_names_w)
@@ -476,8 +479,7 @@
entry = pycode._mapdict_caches[nameindex]
map = w_obj._get_mapdict_map()
if map is entry.map:
- w_type = map.get_terminator().w_cls # XXX fix me, too slow
- version_tag = w_type.version_tag()
+ version_tag = map.w_cls.version_tag()
if version_tag is entry.version_tag:
# everything matches, it's incredibly fast
if pycode.space.config.objspace.std.withmethodcachecounter:
@@ -490,7 +492,7 @@
space = pycode.space
w_name = pycode.co_names_w[nameindex]
if map is not None:
- w_type = map.get_terminator().w_cls
+ w_type = map.w_cls
w_descr = w_type.getattribute_if_not_from_object()
if w_descr is not None:
return space._handle_getattribute(w_descr, w_obj, w_name)
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 Thu Sep 2 20:07:15 2010
@@ -8,9 +8,9 @@
def __init__(self, hasdict=True):
self.hasdict = True
if hasdict:
- self.terminator = DictTerminator(self, space)
+ self.terminator = DictTerminator(space, self)
else:
- self.terminator = NoDictTerminator(self, space)
+ self.terminator = NoDictTerminator(space, self)
def instantiate(self, sp=None):
if sp is None:
@@ -24,7 +24,14 @@
hasdict = False
def test_plain_attribute():
- aa = PlainAttribute(("b", DICT), PlainAttribute(("a", DICT), Terminator(None, None)))
+ space = " "
+ w_cls = "class"
+ aa = PlainAttribute(("b", DICT),
+ PlainAttribute(("a", DICT),
+ Terminator(space, w_cls)))
+ assert aa.space is space
+ assert aa.w_cls is w_cls
+
obj = Object()
obj.map, obj.storage = aa, [10, 20]
assert obj.getdictvalue(space, "a") == 10
Modified: pypy/branch/better-map-instances/pypy/objspace/std/typeobject.py
==============================================================================
--- pypy/branch/better-map-instances/pypy/objspace/std/typeobject.py (original)
+++ pypy/branch/better-map-instances/pypy/objspace/std/typeobject.py Thu Sep 2 20:07:15 2010
@@ -121,9 +121,9 @@
if space.config.objspace.std.withmapdict:
from pypy.objspace.std.mapdict import DictTerminator, NoDictTerminator
if w_self.hasdict:
- w_self.terminator = DictTerminator(w_self, space)
+ w_self.terminator = DictTerminator(space, w_self)
else:
- w_self.terminator = NoDictTerminator(w_self, space)
+ w_self.terminator = NoDictTerminator(space, w_self)
def mutated(w_self):
space = w_self.space
More information about the Pypy-commit
mailing list