[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/generations/utility.py make match code a bit more efficient by using generators

Philipp von Weitershausen philikon at philikon.de
Fri May 12 10:25:22 EDT 2006


Log message for revision 68108:
  make match code a bit more efficient by using generators
  

Changed:
  U   Zope3/trunk/src/zope/app/generations/utility.py

-=-
Modified: Zope3/trunk/src/zope/app/generations/utility.py
===================================================================
--- Zope3/trunk/src/zope/app/generations/utility.py	2006-05-12 11:57:51 UTC (rev 68107)
+++ Zope3/trunk/src/zope/app/generations/utility.py	2006-05-12 14:25:21 UTC (rev 68108)
@@ -64,17 +64,14 @@
     >>> names
     ['a2', 'b2', 'c2']
     """
-    matches = []
     if condition(root):
-        matches.append(root)
+        yield root
 
     if hasattr(root, 'values'):
         for subobj in root.values():
-            matches += findObjectsMatching(subobj, condition)
+            for match in findObjectsMatching(subobj, condition):
+                yield match
 
-    return matches
-
-
 def findObjectsProviding(root, interface):
     """Find all objects in the root that provide the specified interface.
 
@@ -127,4 +124,5 @@
     >>> names
     ['a1', 'a2', 'a3', 'c1', 'c2']
     """
-    return findObjectsMatching(root, interface.providedBy)
+    for match in findObjectsMatching(root, interface.providedBy):
+        yield match



More information about the Zope3-Checkins mailing list