[PATCH 3 of 7] py3: use next() to obtain next item from inner generator of generatorset

Yuya Nishihara yuya at tcha.org
Mon Mar 13 14:59:04 EDT 2017


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1489420411 25200
#      Mon Mar 13 08:53:31 2017 -0700
# Node ID 802478258f49c11e5248baa674bdfd7145882d93
# Parent  c9700b5cb641c10d8b0e6ac90896ebe5cb7c0658
py3: use next() to obtain next item from inner generator of generatorset

.next attribute does not exist on Python 3. As this function seems to really
care about the overhead of the Python interpreter, I follow the way of micro
optimization.

diff --git a/mercurial/smartset.py b/mercurial/smartset.py
--- a/mercurial/smartset.py
+++ b/mercurial/smartset.py
@@ -818,15 +818,15 @@ class generatorset(abstractsmartset):
         # Getting rid of it would provide an about 15% speed up on this
         # iteration.
         genlist = self._genlist
-        nextrev = self._consumegen().next
-        _len = len # cache global lookup
+        nextgen = self._consumegen()
+        _len, _next = len, next # cache global lookup
         def gen():
             i = 0
             while True:
                 if i < _len(genlist):
                     yield genlist[i]
                 else:
-                    yield nextrev()
+                    yield _next(nextgen)
                 i += 1
         return gen()
 


More information about the Mercurial-devel mailing list