[pypy-svn] r19584 - pypy/dist/pypy/interpreter

arigo at codespeak.net arigo at codespeak.net
Sun Nov 6 19:17:29 CET 2005


Author: arigo
Date: Sun Nov  6 19:17:28 2005
New Revision: 19584

Modified:
   pypy/dist/pypy/interpreter/typedef.py
Log:
(pedronis)

cache the created function -- one per class is enough.


Modified: pypy/dist/pypy/interpreter/typedef.py
==============================================================================
--- pypy/dist/pypy/interpreter/typedef.py	(original)
+++ pypy/dist/pypy/interpreter/typedef.py	Sun Nov  6 19:17:28 2005
@@ -200,12 +200,16 @@
     raise OperationError(space.w_TypeError,
                          space.wrap("generic property has no __objclass__"))
 
-def make_objclass_getter(func, cls):
+def make_objclass_getter(func, cls, cache={}):
     if hasattr(func, 'im_func'):
         assert not cls or cls is func.im_class
         cls = func.im_class
     if not cls:
         return unknown_objclass_getter, cls
+    try:
+        return cache[cls]
+    except KeyError:
+        pass
     miniglobals = {}
     if isinstance(cls, str):
         assert cls.startswith('<'),"pythontype typecheck should begin with <"
@@ -219,7 +223,9 @@
             return %s
         \n""" % (typeexpr,)
     exec compile2(source) in miniglobals
-    return miniglobals['objclass_getter'], cls
+    res = miniglobals['objclass_getter'], cls
+    cache[cls] = res
+    return res
 
 class GetSetProperty(Wrappable):
     def __init__(self, fget, fset=None, fdel=None, doc=None, cls=None):



More information about the Pypy-commit mailing list