Mercurial > public > mercurial-scm > hg
comparison mercurial/revset.py @ 22670:44dce874de97
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.
author | Pierre-Yves David <pierre-yves.david@fb.com> |
---|---|
date | Wed, 30 Apr 2014 16:56:23 -0700 |
parents | 00c8abe64cf3 |
children | 2717dcff7be1 |
comparison
equal
deleted
inserted
replaced
22669:00c8abe64cf3 | 22670:44dce874de97 |
---|---|
2653 self._cache[x] = False | 2653 self._cache[x] = False |
2654 return False | 2654 return False |
2655 | 2655 |
2656 def __iter__(self): | 2656 def __iter__(self): |
2657 if self._finished: | 2657 if self._finished: |
2658 for x in self._genlist: | 2658 return iter(self._genlist) |
2659 yield x | |
2660 return | |
2661 | 2659 |
2662 # We have to use this complex iteration strategy to allow multiple | 2660 # We have to use this complex iteration strategy to allow multiple |
2663 # iterations at the same time. We need to be able to catch revision | 2661 # iterations at the same time. We need to be able to catch revision |
2664 # removed from `consumegen` and added to genlist in another instance. | 2662 # removed from `consumegen` and added to genlist in another instance. |
2665 # | 2663 # |
2666 # Getting rid of it would provide an about 15% speed up on this | 2664 # Getting rid of it would provide an about 15% speed up on this |
2667 # iteration. | 2665 # iteration. |
2668 i = 0 | |
2669 genlist = self._genlist | 2666 genlist = self._genlist |
2670 nextrev = self._consumegen().next | 2667 nextrev = self._consumegen().next |
2671 _len = len # cache global lookup | 2668 _len = len # cache global lookup |
2672 while True: | 2669 def gen(): |
2673 if i < _len(genlist): | 2670 i = 0 |
2674 yield genlist[i] | 2671 while True: |
2675 else: | 2672 if i < _len(genlist): |
2676 yield nextrev() | 2673 yield genlist[i] |
2677 i += 1 | 2674 else: |
2675 yield nextrev() | |
2676 i += 1 | |
2677 return gen() | |
2678 | 2678 |
2679 def _consumegen(self): | 2679 def _consumegen(self): |
2680 cache = self._cache | 2680 cache = self._cache |
2681 genlist = self._genlist.append | 2681 genlist = self._genlist.append |
2682 for item in self._gen: | 2682 for item in self._gen: |