diff mercurial/smartset.py @ 32839: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
line wrap: on
line diff
--- a/mercurial/smartset.py	Tue Mar 24 00:14:53 2015 +0900
+++ b/mercurial/smartset.py	Thu Apr 09 23:56:06 2015 +0900
@@ -372,6 +372,18 @@
     def __sub__(self, other):
         return self._fastsetop(other, '__sub__')
 
+    def _slice(self, start, stop):
+        # creating new list should be generally cheaper than iterating items
+        if self._ascending is None:
+            return baseset(self._list[start:stop], istopo=self._istopo)
+
+        data = self._asclist
+        if not self._ascending:
+            start, stop = max(len(data) - stop, 0), max(len(data) - start, 0)
+        s = baseset(data[start:stop], istopo=self._istopo)
+        s._ascending = self._ascending
+        return s
+
     def __repr__(self):
         d = {None: '', False: '-', True: '+'}[self._ascending]
         s = _formatsetrepr(self._datarepr)