Patchwork [2,of,3] revset: use spanset.isdescending in multiple simple places

login
register
mail settings
Submitter Pierre-Yves David
Date Sept. 18, 2014, 6:26 p.m.
Message ID <862bc6d9cdea929b80bf.1411064785@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/5869/
State Accepted
Headers show

Comments

Pierre-Yves David - Sept. 18, 2014, 6:26 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1410935823 25200
#      Tue Sep 16 23:37:03 2014 -0700
# Node ID 862bc6d9cdea929b80bf3635f8b66d7b39ebd6ad
# Parent  b885794378e462baab1967d19106615d0acf6689
revset: use spanset.isdescending in multiple simple places

We call the method directly instead of duplicating checks.

Benchmarks show no performances harmed in the process.

Patch

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -2745,19 +2745,19 @@  class spanset(_orderedsetmixin):
         else:
             self._end = len(repo)
         self._hiddenrevs = repo.changelog.filteredrevs
 
     def ascending(self):
-        if self._start > self._end:
+        if not self.isascending():
             self.reverse()
 
     def descending(self):
-        if self._start < self._end:
+        if not self.isdescending():
             self.reverse()
 
     def __iter__(self):
-        if self._start <= self._end:
+        if self.isascending():
             iterrange = xrange(self._start, self._end)
         else:
             iterrange = xrange(self._start, self._end, -1)
 
         if self._hiddenrevs:
@@ -2824,11 +2824,11 @@  class spanset(_orderedsetmixin):
         if bool(reverse) != (self._start > self._end):
             self.reverse()
 
     def reverse(self):
         # Just switch the _start and _end parameters
-        if self._start <= self._end:
+        if self.isascending():
             self._start, self._end = self._end - 1, self._start - 1
         else:
             self._start, self._end = self._end + 1, self._start + 1
 
     def set(self):