comparison mercurial/revset.py @ 22669:00c8abe64cf3

revset: prefetch an attribute in _generatorset.__iter__ Python's attribute lookup are expensible, lets do less of them. This gives us a 7% speedup on this revset iteration (from 0.063403 to 0.059032)
author Pierre-Yves David <pierre-yves.david@fb.com>
date Thu, 18 Sep 2014 15:52:45 -0700
parents 6f434ef54222
children 44dce874de97
comparison
equal deleted inserted replaced
22668:13e3f07d74a3 22669:00c8abe64cf3
2665 # 2665 #
2666 # Getting rid of it would provide an about 15% speed up on this 2666 # Getting rid of it would provide an about 15% speed up on this
2667 # iteration. 2667 # iteration.
2668 i = 0 2668 i = 0
2669 genlist = self._genlist 2669 genlist = self._genlist
2670 consume = self._consumegen() 2670 nextrev = self._consumegen().next
2671 _len = len # cache global lookup
2671 while True: 2672 while True:
2672 if i < len(genlist): 2673 if i < _len(genlist):
2673 yield genlist[i] 2674 yield genlist[i]
2674 else: 2675 else:
2675 yield consume.next() 2676 yield nextrev()
2676 i += 1 2677 i += 1
2677 2678
2678 def _consumegen(self): 2679 def _consumegen(self):
2679 cache = self._cache 2680 cache = self._cache
2680 genlist = self._genlist.append 2681 genlist = self._genlist.append