comparison mercurial/smartset.py @ 32820:653d60455dbe

smartset: micro optimize baseset.slice() to use slice of list -1ms isn't significant, but seems not bad. revset #1: limit(0::9999, 100, 9000) 5) 0.001681 6) 0.000790
author Yuya Nishihara <yuya@tcha.org>
date Thu, 09 Apr 2015 23:56:06 +0900
parents 4710cc4dac99
children 9b7d615108d7
comparison
equal deleted inserted replaced
32819:4710cc4dac99 32820:653d60455dbe
369 def __and__(self, other): 369 def __and__(self, other):
370 return self._fastsetop(other, '__and__') 370 return self._fastsetop(other, '__and__')
371 371
372 def __sub__(self, other): 372 def __sub__(self, other):
373 return self._fastsetop(other, '__sub__') 373 return self._fastsetop(other, '__sub__')
374
375 def _slice(self, start, stop):
376 # creating new list should be generally cheaper than iterating items
377 if self._ascending is None:
378 return baseset(self._list[start:stop], istopo=self._istopo)
379
380 data = self._asclist
381 if not self._ascending:
382 start, stop = max(len(data) - stop, 0), max(len(data) - start, 0)
383 s = baseset(data[start:stop], istopo=self._istopo)
384 s._ascending = self._ascending
385 return s
374 386
375 def __repr__(self): 387 def __repr__(self):
376 d = {None: '', False: '-', True: '+'}[self._ascending] 388 d = {None: '', False: '-', True: '+'}[self._ascending]
377 s = _formatsetrepr(self._datarepr) 389 s = _formatsetrepr(self._datarepr)
378 if not s: 390 if not s: