[PATCH 3 of 4] revset: rely on built in iterator when possible in _generatorset.__iter__
Pierre-Yves David
pierre-yves.david at ens-lyon.org
Fri Sep 19 15:42:11 CDT 2014
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at fb.com>
# Date 1398902183 25200
# Wed Apr 30 16:56:23 2014 -0700
# Node ID e3e71e54d41fc10e5cd95fe0ea6f3c471c09ca67
# Parent 5923ec85150027d51233f04ecc2b59bfa69d2a40
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.
diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -2643,29 +2643,29 @@ class _generatorset(object):
self._cache[x] = False
return False
def __iter__(self):
if self._finished:
- for x in self._genlist:
- yield x
- return
+ return iter(self._genlist)
# we have to use this complexe iteration strategy to allow multiple
# iteration at the same time. We need to be able to catch revision
# removed from `consumegen` and added to genlist in another instance.
#
# Getting ride of it would provide an about 15% speed up on this
# iteration.
- i = 0
genlist = self._genlist
nextrev = self._consumegen().next
- 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):
for item in self._gen:
self._cache[item] = True
self._genlist.append(item)
More information about the Mercurial-devel
mailing list