Commits

Mike Bayer committed cf004ac

turn iterate() into a "legit" breadth-first traversal

Comments (0)

Files changed (1)

lib/sqlalchemy/sql/visitors.py

     def traverse_single(self, obj):
         for v in self._iterate_visitors:
             meth = getattr(v, "visit_%s" % obj.__visit_name__, None)
-            #meth = v._registry.get(obj.__visit_name__, None)
             if meth:
                 return meth(obj)
     
 def iterate(obj, opts):
     """traverse the given expression structure, returning an iterator."""
 
-    stack = [obj]
+    stack = util.deque([obj])
     while stack:
-        t = stack.pop()
+        t = stack.popleft()
         yield t
         for c in t.get_children(**opts):
             stack.append(c)
     traversal is configured to be depth-first.
     
     """
-    stack = [obj]
+    stack = util.deque([obj])
     traversal = util.deque()
     while stack:
         t = stack.pop()