[Checkins] SVN: z3c.autoinclude/branches/optimization-sandbox/src/z3c/autoinclude/utils.py cache values for find_packages and find_distributions, just on a hunch

Ethan Jucovy ejucovy at openplans.org
Fri Apr 10 13:11:52 EDT 2009


Log message for revision 99097:
  cache values for find_packages and find_distributions, just on a hunch

Changed:
  U   z3c.autoinclude/branches/optimization-sandbox/src/z3c/autoinclude/utils.py

-=-
Modified: z3c.autoinclude/branches/optimization-sandbox/src/z3c/autoinclude/utils.py
===================================================================
--- z3c.autoinclude/branches/optimization-sandbox/src/z3c/autoinclude/utils.py	2009-04-10 16:43:19 UTC (rev 99096)
+++ z3c.autoinclude/branches/optimization-sandbox/src/z3c/autoinclude/utils.py	2009-04-10 17:11:52 UTC (rev 99097)
@@ -166,3 +166,14 @@
         from fnmatch import fnmatchcase
         out = [item for item in out if not fnmatchcase(item,pat)]
     return out
+
+def cached(func):
+    cache = {}
+    def inner(*args):
+        if (func, args) not in cache:
+            cache[(func, args)] = list(func(*args)) #guard against generators
+        return cache[(func, args)]
+    return inner
+
+find_packages = cached(find_packages)
+find_distributions = cached(find_distributions)



More information about the Checkins mailing list