changeset 32821:9b7d615108d7

smartset: micro optimize spanset.slice() to narrow range accordingly -1ms isn't significant, but seems not bad. revset #0: limit(0:9999, 100, 9000) 6) 0.001145 7) 0.000214 revset #3: last(0:9999, 100) 6) 0.000197 7) 0.000171
author Yuya Nishihara <yuya@tcha.org>
date Fri, 10 Apr 2015 00:14:16 +0900
parents 653d60455dbe
children e65ff29dbeb0
files mercurial/smartset.py tests/test-revset.t
diffstat 2 files changed, 58 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/smartset.py	Thu Apr 09 23:56:06 2015 +0900
+++ b/mercurial/smartset.py	Fri Apr 10 00:14:16 2015 +0900
@@ -1056,6 +1056,18 @@
             return x
         return None
 
+    def _slice(self, start, stop):
+        if self._hiddenrevs:
+            # unoptimized since all hidden revisions in range has to be scanned
+            return super(_spanset, self)._slice(start, stop)
+        if self._ascending:
+            x = min(self._start + start, self._end)
+            y = min(self._start + stop, self._end)
+        else:
+            x = max(self._end - stop, self._start)
+            y = max(self._end - start, self._start)
+        return _spanset(x, y, self._ascending, self._hiddenrevs)
+
     def __repr__(self):
         d = {False: '-', True: '+'}[self._ascending]
         return '<%s%s %d:%d>' % (type(self).__name__.lstrip('_'), d,
--- a/tests/test-revset.t	Thu Apr 09 23:56:06 2015 +0900
+++ b/tests/test-revset.t	Fri Apr 10 00:14:16 2015 +0900
@@ -1080,13 +1080,54 @@
   * set:
   <baseset+ []>
 
+ (using spanset)
+
+  $ hg debugrevspec --no-show-revs -s 0:7
+  * set:
+  <spanset+ 0:8>
+  $ log 'limit(0:7, 3, 4)'
+  4
+  5
+  6
+  $ log 'limit(7:0, 3, 4)'
+  3
+  2
+  1
+  $ log 'limit(0:7, 3, 6)'
+  6
+  7
+  $ log 'limit(7:0, 3, 6)'
+  1
+  0
+  $ log 'last(0:7, 2)'
+  6
+  7
+  $ hg debugrevspec -s 'limit(0:7, 3, 6)'
+  * set:
+  <spanset+ 6:8>
+  6
+  7
+  $ hg debugrevspec -s 'limit(0:7, 3, 9)'
+  * set:
+  <spanset+ 8:8>
+  $ hg debugrevspec -s 'limit(7:0, 3, 6)'
+  * set:
+  <spanset- 0:2>
+  1
+  0
+  $ hg debugrevspec -s 'limit(7:0, 3, 9)'
+  * set:
+  <spanset- 0:0>
+  $ hg debugrevspec -s 'limit(0:7, 0)'
+  * set:
+  <spanset+ 0:0>
+
 Test order of first/last revisions
 
   $ hg debugrevspec -s 'first(4:0, 3) & 3:'
   * set:
   <filteredset
-    <baseset slice=0:3
-      <spanset- 0:5>>,
+    <spanset- 2:5>,
     <spanset+ 3:10>>
   4
   3
@@ -1095,16 +1136,14 @@
   * set:
   <filteredset
     <spanset+ 3:10>,
-    <baseset slice=0:3
-      <spanset- 0:5>>>
+    <spanset- 2:5>>
   3
   4
 
   $ hg debugrevspec -s 'last(4:0, 3) & :1'
   * set:
   <filteredset
-    <baseset slice=0:3
-      <spanset+ 0:5>>,
+    <spanset- 0:3>,
     <spanset+ 0:2>>
   1
   0
@@ -1113,8 +1152,7 @@
   * set:
   <filteredset
     <spanset+ 0:2>,
-    <baseset slice=0:3
-      <spanset+ 0:5>>>
+    <spanset+ 0:3>>
   0
   1