revset: changed generatorset code to remove unnecesary function call
authorLucas Moscovicz <lmoscovicz@fb.com>
Mon, 03 Mar 2014 12:54:46 -0800
changeset 20634 f2bb7ba59456
parent 20632 e993f065e17c
child 20635 7cd956ace1f4
revset: changed generatorset code to remove unnecesary function call Removed _nextitem() method, now __iter__ has that logic and __contains__ uses __iter__ to check for membership.
mercurial/revset.py
--- a/mercurial/revset.py	Mon Mar 03 15:50:41 2014 +0900
+++ b/mercurial/revset.py	Mon Mar 03 12:54:46 2014 -0800
@@ -2270,24 +2270,13 @@
         self._genlist = baseset([])
         self._iterated = False
 
-    def _nextitem(self):
-        l = self._iter.next()
-        self._cache[l] = True
-        self._genlist.append(l)
-        return l
-
     def __contains__(self, x):
         if x in self._cache:
             return self._cache[x]
 
-        self._iterated = True
-        while True:
-            try:
-                l = self._nextitem()
-                if l == x:
-                    return True
-            except (StopIteration):
-                break
+        for l in self:
+            if l == x:
+                return True
 
         self._cache[x] = False
         return False
@@ -2296,18 +2285,13 @@
         if self._iterated:
             for l in self._genlist:
                 yield l
-            while True:
-                try:
-                    item = self._nextitem()
-                    yield item
-                except (StopIteration):
-                    break
         else:
             self._iterated = True
-            for item in self._gen:
-                self._cache[item] = True
-                self._genlist.append(item)
-                yield item
+
+        for item in self._gen:
+            self._cache[item] = True
+            self._genlist.append(item)
+            yield item
 
     def set(self):
         return self