[pypy-commit] pypy SpecialisedTuples: (mwp) move try_specialisation to be a class method of specialised class, and unroll specialisation loop
mwp
noreply at buildbot.pypy.org
Thu Nov 10 10:48:01 CET 2011
Author: Mark Pearse <mark.pearse at skynet.be>
Branch: SpecialisedTuples
Changeset: r49112:06891784efa2
Date: 2011-11-08 15:52 +0100
http://bitbucket.org/pypy/pypy/changeset/06891784efa2/
Log: (mwp) move try_specialisation to be a class method of specialised
class, and unroll specialisation loop
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
@@ -14,21 +14,9 @@
_specialisations = []
def makespecialisedtuple(space, list_w):
- w_type_of = {int:space.w_int, float:space.w_float, str:space.w_str}
- unwrap_as = {int:space.int_w, float:space.float_w, str:space.str_w}
-
- def try_specialisation((specialisedClass, paramtypes)):
- if len(list_w) != len(paramtypes):
- raise NotSpecialised
- for param,paramtype in zip(list_w,paramtypes):
- if space.type(param) != w_type_of[paramtype]:
- raise NotSpecialised
- unwrappedparams = [unwrap_as[paramtype](param) for param,paramtype in zip(list_w,paramtypes)]
- return specialisedClass(space, *unwrappedparams)
-
- for spec in _specialisations:
+ for specialisedClass,paramtypes in unrolling_iterable(_specialisations):
try:
- return try_specialisation(spec)
+ return specialisedClass.try_specialisation(space, paramtypes, list_w)
except NotSpecialised:
pass
raise NotSpecialised
@@ -73,6 +61,22 @@
self.space = space
for i in iter_n:
setattr(self, 'value%s' % i, values[i])
+
+ @classmethod
+ def try_specialisation(specialisedClass, space, paramtypes, paramlist):
+
+
+ _w_type_of = {int:space.w_int, float:space.w_float, str:space.w_str}
+ _unwrap_as = {int:space.int_w, float:space.float_w, str:space.str_w}
+
+
+ if len(paramlist) != len(paramtypes):
+ raise NotSpecialised
+ for param,paramtype in zip(paramlist, paramtypes):
+ if space.type(param) != _w_type_of[paramtype]:
+ raise NotSpecialised
+ unwrappedparams = [_unwrap_as[paramtype](param) for param,paramtype in zip(paramlist, paramtypes)]
+ return specialisedClass(space, *unwrappedparams)
def length(self):
return len(typetuple)
More information about the pypy-commit
mailing list