[pypy-svn] r32665 - in pypy/dist/pypy: interpreter objspace/std
ac at codespeak.net
ac at codespeak.net
Wed Sep 27 13:11:32 CEST 2006
Author: ac
Date: Wed Sep 27 13:11:31 2006
New Revision: 32665
Modified:
pypy/dist/pypy/interpreter/typedef.py
pypy/dist/pypy/objspace/std/objspace.py
Log:
(pedronis, arre)
Reduce the number of RPython classes created for every user subclassable type.
Modified: pypy/dist/pypy/interpreter/typedef.py
==============================================================================
--- pypy/dist/pypy/interpreter/typedef.py (original)
+++ pypy/dist/pypy/interpreter/typedef.py Wed Sep 27 13:11:31 2006
@@ -87,9 +87,18 @@
no_hash_descr = interp2app(descr__hash__unhashable)
# ____________________________________________________________
-
def get_unique_interplevel_subclass(cls, hasdict, wants_slots, needsdel=False,
weakrefable=False):
+ if needsdel:
+ hasdict = wants_slots = weakrefable = True
+ if hasdict:
+ weakrefable = True
+ else:
+ wants_slots = True
+ return _get_unique_interplevel_subclass(cls, hasdict, wants_slots, needsdel, weakrefable)
+get_unique_interplevel_subclass._annspecialcase_ = "specialize:memo"
+
+def _get_unique_interplevel_subclass(cls, hasdict, wants_slots, needsdel, weakrefable):
key = cls, hasdict, wants_slots, needsdel, weakrefable
try:
return _subclass_cache[key]
@@ -97,7 +106,6 @@
subcls = _buildusercls(cls, hasdict, wants_slots, needsdel, weakrefable)
_subclass_cache[key] = subcls
return subcls
-get_unique_interplevel_subclass._annspecialcase_ = "specialize:memo"
_subclass_cache = {}
def _buildusercls(cls, hasdict, wants_slots, wants_del, weakrefable):
@@ -123,7 +131,7 @@
name = ''.join(name)
if weakrefable:
- supercls = get_unique_interplevel_subclass(cls, hasdict, wants_slots,
+ supercls = _get_unique_interplevel_subclass(cls, hasdict, wants_slots,
wants_del, False)
class Proto(object):
_lifeline_ = None
@@ -132,7 +140,7 @@
def setweakref(self, space, weakreflifeline):
self._lifeline_ = weakreflifeline
elif wants_del:
- supercls = get_unique_interplevel_subclass(cls, hasdict, wants_slots,
+ supercls = _get_unique_interplevel_subclass(cls, hasdict, wants_slots,
False, False)
parent_destructor = getattr(cls, '__del__', None)
class Proto(object):
@@ -145,11 +153,13 @@
if parent_destructor is not None:
parent_destructor(self)
elif wants_slots:
- supercls = get_unique_interplevel_subclass(cls, hasdict, False, False, False)
+ supercls = _get_unique_interplevel_subclass(cls, hasdict, False, False, False)
class Proto(object):
+ slots_w = None
def user_setup_slots(self, nslots):
- self.slots_w = [None] * nslots
+ if nslots > 0:
+ self.slots_w = [None] * nslots
def setslotvalue(self, index, w_value):
self.slots_w[index] = w_value
@@ -157,7 +167,7 @@
def getslotvalue(self, index):
return self.slots_w[index]
elif hasdict:
- supercls = get_unique_interplevel_subclass(cls, False, False, False, False)
+ supercls = _get_unique_interplevel_subclass(cls, False, False, False, False)
class Proto(object):
def getdict(self):
@@ -169,11 +179,11 @@
space.wrap("setting dictionary to a non-dict"))
self.w__dict__ = w_dict
- def user_setup(self, space, w_subtype, nslots):
+ def user_setup(self, space, w_subtype):
self.space = space
self.w__class__ = w_subtype
self.w__dict__ = space.newdict()
- self.user_setup_slots(nslots)
+ self.user_setup_slots(w_subtype.nslots)
else:
supercls = cls
@@ -187,10 +197,10 @@
self.w__class__ = w_subtype
- def user_setup(self, space, w_subtype, nslots):
+ def user_setup(self, space, w_subtype):
self.space = space
self.w__class__ = w_subtype
- self.user_setup_slots(nslots)
+ self.user_setup_slots(w_subtype.nslots)
def user_setup_slots(self, nslots):
assert nslots == 0
Modified: pypy/dist/pypy/objspace/std/objspace.py
==============================================================================
--- pypy/dist/pypy/objspace/std/objspace.py (original)
+++ pypy/dist/pypy/objspace/std/objspace.py Wed Sep 27 13:11:31 2006
@@ -438,7 +438,7 @@
w_subtype = w_type.check_user_subclass(w_subtype)
subcls = get_unique_interplevel_subclass(cls, w_subtype.hasdict, w_subtype.nslots != 0, w_subtype.needsdel, w_subtype.weakrefable)
instance = instantiate(subcls)
- instance.user_setup(self, w_subtype, w_subtype.nslots)
+ instance.user_setup(self, w_subtype)
else:
raise OperationError(self.w_TypeError,
self.wrap("%s.__new__(%s): only for the type %s" % (
More information about the Pypy-commit
mailing list