changeset 20634:f2bb7ba59456

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.
author Lucas Moscovicz <lmoscovicz@fb.com>
date Mon, 03 Mar 2014 12:54:46 -0800
parents e993f065e17c
children 7cd956ace1f4
files mercurial/revset.py
diffstat 1 files changed, 8 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- 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