comparison mercurial/revset.py @ 22827:c1107cb21df2

baseset: prepare lazy ordering in __iter__ We'll explicitly track the order of the baseset to take advantage of the ascending and descending lists during iteration.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Fri, 03 Oct 2014 03:26:18 -0500
parents 4ffb327e4719
children 966860f7a1a8
comparison
equal deleted inserted replaced
22826:4ffb327e4719 22827:c1107cb21df2
2329 def __init__(self, data=()): 2329 def __init__(self, data=()):
2330 if not isinstance(data, list): 2330 if not isinstance(data, list):
2331 data = list(data) 2331 data = list(data)
2332 self._list = data 2332 self._list = data
2333 self._set = None 2333 self._set = None
2334 self._ascending = None
2334 2335
2335 @util.propertycache 2336 @util.propertycache
2336 def _asclist(self): 2337 def _asclist(self):
2337 asclist = self._list[:] 2338 asclist = self._list[:]
2338 asclist.sort() 2339 asclist.sort()
2339 return asclist 2340 return asclist
2340 2341
2342 def __iter__(self):
2343 if self._ascending is None:
2344 return iter(self._list)
2345 elif self._ascending:
2346 return iter(self._asclist)
2347 else:
2348 return reversed(self._asclist)
2349
2341 def fastasc(self): 2350 def fastasc(self):
2342 return iter(self._asclist) 2351 return iter(self._asclist)
2343 2352
2344 def fastdesc(self): 2353 def fastdesc(self):
2345 return reversed(self._asclist) 2354 return reversed(self._asclist)
2365 def sort(self, reverse=False): 2374 def sort(self, reverse=False):
2366 self._list.sort(reverse=reverse) 2375 self._list.sort(reverse=reverse)
2367 2376
2368 def reverse(self): 2377 def reverse(self):
2369 self._list.reverse() 2378 self._list.reverse()
2370
2371 def __iter__(self):
2372 return iter(self._list)
2373 2379
2374 def __len__(self): 2380 def __len__(self):
2375 return len(self._list) 2381 return len(self._list)
2376 2382
2377 def __sub__(self, other): 2383 def __sub__(self, other):