[pypy-svn] r9525 - pypy/dist/pypy/objspace/std

hpk at codespeak.net hpk at codespeak.net
Mon Feb 28 16:52:02 CET 2005


Author: hpk
Date: Mon Feb 28 16:52:01 2005
New Revision: 9525

Modified:
   pypy/dist/pypy/objspace/std/multimethod.py
Log:
hands-on-hack to avoid the many duplicate functions+globals 
which arise on multimethod construction.  Maybe there is 
a nicer way to avoid the occurence of the duplicate definitions? 



Modified: pypy/dist/pypy/objspace/std/multimethod.py
==============================================================================
--- pypy/dist/pypy/objspace/std/multimethod.py	(original)
+++ pypy/dist/pypy/objspace/std/multimethod.py	Mon Feb 28 16:52:01 2005
@@ -91,6 +91,7 @@
 # ____________________________________________________________
 
 class Installer:
+    mmfunccache = {}
 
     prefix_memo = {}
 
@@ -251,9 +252,19 @@
         bodylines.insert(0, 'def %s(%s):' % (funcname, ', '.join(funcargs)))
         bodylines.append('')
         source = '\n'.join(bodylines)
-        #print source
-        #print "*"*60
-        exec compile2(source) in miniglobals
-        func = miniglobals[funcname]
+
+        # XXX find a better place (or way) to avoid duplicate functions 
+        l = miniglobals.items()
+        l.sort()
+        l = tuple(l)
+        key = (source, l)
+        try: 
+            func = self.mmfunccache[key]
+        except KeyError: 
+            exec compile2(source) in miniglobals
+            func = miniglobals[funcname]
+            self.mmfunccache[key] = func 
+        #else: 
+        #    print "avoided duplicate function", func
         self.to_install.append((target, funcname, func, source, fallback))
         return func



More information about the Pypy-commit mailing list