comparison mercurial/revset.py @ 24936:2aa94b6fe51c

revset: make generatorset.__nonzero__ lazy The 'for r in self:' call could trigger full consumption of the generator while we only need a single value. We also fast path if a single value got already computed. See inline comment for more details. This provide massive speedup for lazy operation using boolean testing. max(::tip) e5b507efb36e) wall 0.055609 comb 0.060000 user 0.060000 sys 0.000000 (best of 100) after change) wall 0.000109 comb 0.000000 user 0.000000 sys 0.000000 (best of 19146)
author Pierre-Yves David <pierre-yves.david@fb.com>
date Mon, 04 May 2015 12:36:48 -0700
parents 022282152632
children f5518b47cdd1
comparison
equal deleted inserted replaced
24935:3035b75cd594 24936:2aa94b6fe51c
3135 else: 3135 else:
3136 self.fastdesc = self._iterator 3136 self.fastdesc = self._iterator
3137 self.__contains__ = self._desccontains 3137 self.__contains__ = self._desccontains
3138 3138
3139 def __nonzero__(self): 3139 def __nonzero__(self):
3140 for r in self: 3140 # Do not use 'for r in self' because it will enforce the iteration
3141 # order (default ascending), possibly unrolling a whole descending
3142 # iterator.
3143 if self._genlist:
3144 return True
3145 for r in self._consumegen():
3141 return True 3146 return True
3142 return False 3147 return False
3143 3148
3144 def __contains__(self, x): 3149 def __contains__(self, x):
3145 if x in self._cache: 3150 if x in self._cache: