Patchwork [1,of,2] revset: changed generatorset code to remove unnecesary function call

login
register
mail settings
Submitter Lucas Moscovicz
Date March 3, 2014, 9:10 p.m.
Message ID <d4364169b474c6e7a17e.1393881012@dev1037.prn2.facebook.com>
Download mbox | patch
Permalink /patch/3837/
State Accepted
Commit f2bb7ba5945699e332d9b78d619bac87b7287874
Headers show

Comments

Lucas Moscovicz - March 3, 2014, 9:10 p.m.
# HG changeset patch
# User Lucas Moscovicz <lmoscovicz@fb.com>
# Date 1393880086 28800
#      Mon Mar 03 12:54:46 2014 -0800
# Node ID d4364169b474c6e7a17e3e8656d368998b76ae44
# Parent  c36640f9a678ab7bd96ed92a66e0377e24e71b8d
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.

Patch

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -2281,24 +2281,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
@@ -2307,18 +2296,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