##// END OF EJS Templates
spanset: enforce the order lazily to gain `fastasc` and `fastdesc` methods...
Pierre-Yves David -
r22717:b89f7e3a default
parent child Browse files
Show More
@@ -2855,27 +2855,44 class _spanset(_orderedsetmixin, abstrac
2855
2855
2856 Spanset will be descending if `end` < `start`.
2856 Spanset will be descending if `end` < `start`.
2857 """
2857 """
2858 if end is None:
2859 end = len(repo)
2860 self._ascending = start <= end
2861 if not self._ascending:
2862 start, end = end + 1, start +1
2858 self._start = start
2863 self._start = start
2859 if end is not None:
2864 self._end = end
2860 self._end = end
2861 else:
2862 self._end = len(repo)
2863 self._hiddenrevs = repo.changelog.filteredrevs
2865 self._hiddenrevs = repo.changelog.filteredrevs
2864
2866
2867 def sort(self, reverse=False):
2868 self._ascending = not reverse
2869
2870 def reverse(self):
2871 self._ascending = not self._ascending
2872
2873 def _iterfilter(self, iterrange):
2874 s = self._hiddenrevs
2875 for r in iterrange:
2876 if r not in s:
2877 yield r
2878
2865 def __iter__(self):
2879 def __iter__(self):
2866 if self.isascending():
2880 if self._ascending:
2867 iterrange = xrange(self._start, self._end)
2881 return self.fastasc()
2868 else:
2882 else:
2869 iterrange = xrange(self._start, self._end, -1)
2883 return self.fastdesc()
2870
2884
2885 def fastasc(self):
2886 iterrange = xrange(self._start, self._end)
2871 if self._hiddenrevs:
2887 if self._hiddenrevs:
2872 s = self._hiddenrevs
2888 return self._iterfilter(iterrange)
2873 for r in iterrange:
2889 return iter(iterrange)
2874 if r not in s:
2890
2875 yield r
2891 def fastdesc(self):
2876 else:
2892 iterrange = xrange(self._end - 1, self._start - 1, -1)
2877 for r in iterrange:
2893 if self._hiddenrevs:
2878 yield r
2894 return self._iterfilter(iterrange)
2895 return iter(iterrange)
2879
2896
2880 def __contains__(self, rev):
2897 def __contains__(self, rev):
2881 start = self._start
2898 start = self._start
@@ -2923,17 +2940,6 class _spanset(_orderedsetmixin, abstrac
2923 l = baseset([r for r in self])
2940 l = baseset([r for r in self])
2924 return l[x]
2941 return l[x]
2925
2942
2926 def sort(self, reverse=False):
2927 if bool(reverse) != (self._start > self._end):
2928 self.reverse()
2929
2930 def reverse(self):
2931 # Just switch the _start and _end parameters
2932 if self.isascending():
2933 self._start, self._end = self._end - 1, self._start - 1
2934 else:
2935 self._start, self._end = self._end + 1, self._start + 1
2936
2937 def set(self):
2943 def set(self):
2938 return self
2944 return self
2939
2945
General Comments 0
You need to be logged in to leave comments. Login now