revset: rely on built in iterator when possible in _generatorset.__iter__
authorPierre-Yves David <pierre-yves.david@fb.com>
Wed, 30 Apr 2014 16:56:23 -0700
changeset 22670 44dce874de97
parent 22669 00c8abe64cf3
child 22671 5220c12c43fd
revset: rely on built in iterator when possible in _generatorset.__iter__ Doing manual iteration is expensible. We rely on built in list iteration whenever possible. The other case has to become a closure we cannot have a both yield and return in the same function.
mercurial/revset.py
--- a/mercurial/revset.py	Thu Sep 18 15:52:45 2014 -0700
+++ b/mercurial/revset.py	Wed Apr 30 16:56:23 2014 -0700
@@ -2655,9 +2655,7 @@
 
     def __iter__(self):
         if self._finished:
-            for x in self._genlist:
-                yield x
-            return
+            return iter(self._genlist)
 
         # We have to use this complex iteration strategy to allow multiple
         # iterations at the same time. We need to be able to catch revision
@@ -2665,16 +2663,18 @@
         #
         # Getting rid of it would provide an about 15% speed up on this
         # iteration.
-        i = 0
         genlist = self._genlist
         nextrev = self._consumegen().next
         _len = len # cache global lookup
-        while True:
-            if i < _len(genlist):
-                yield genlist[i]
-            else:
-                yield nextrev()
-            i += 1
+        def gen():
+            i = 0
+            while True:
+                if i < _len(genlist):
+                    yield genlist[i]
+                else:
+                    yield nextrev()
+                i += 1
+        return gen()
 
     def _consumegen(self):
         cache = self._cache