Patchwork [3,of,3] revset: simplify orderedlazyset creation in spanset method

login
register
mail settings
Submitter Pierre-Yves David
Date Sept. 18, 2014, 6:26 p.m.
Message ID <d26e9a84e752ca0eaa25.1411064786@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/5870/
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 1410936454 25200
#      Tue Sep 16 23:47:34 2014 -0700
# Node ID d26e9a84e752ca0eaa2533d9a3fd3ab614e17b38
# Parent  862bc6d9cdea929b80bf3635f8b66d7b39ebd6ad
revset: simplify orderedlazyset creation in spanset method

We can simply use the `self.isascending` value instead of more complex if/else
clause. This get the code simpler.

Benchmarks show no performances harmed in the process.
Durham Goode - Sept. 18, 2014, 7:32 p.m.
On 9/18/14, 11:26 AM, Pierre-Yves David wrote:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david@fb.com>
> # Date 1410936454 25200
> #      Tue Sep 16 23:47:34 2014 -0700
> # Node ID d26e9a84e752ca0eaa2533d9a3fd3ab614e17b38
> # Parent  862bc6d9cdea929b80bf3635f8b66d7b39ebd6ad
> revset: simplify orderedlazyset creation in spanset method
>
> We can simply use the `self.isascending` value instead of more complex if/else
> clause. This get the code simpler.
>
> Benchmarks show no performances harmed in the process.
>
Queued this series to the clowncopter repo.  Verified there were no 
performance changes in my repo, too.

Patch

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -2780,22 +2780,18 @@  class spanset(_orderedsetmixin):
         return False
 
     def __and__(self, x):
         if isinstance(x, baseset):
             x = x.set()
-        if self._start <= self._end:
-            return orderedlazyset(self, x.__contains__)
-        else:
-            return orderedlazyset(self, x.__contains__, ascending=False)
+        return orderedlazyset(self, x.__contains__,
+                              ascending=self.isascending())
 
     def __sub__(self, x):
         if isinstance(x, baseset):
             x = x.set()
-        if self._start <= self._end:
-            return orderedlazyset(self, lambda r: r not in x)
-        else:
-            return orderedlazyset(self, lambda r: r not in x, ascending=False)
+        return orderedlazyset(self, lambda r: r not in x,
+                              ascending=self.isascending())
 
     def __add__(self, x):
         kwargs = {}
         if self.isascending() and x.isascending():
             kwargs['ascending'] = True
@@ -2839,12 +2835,9 @@  class spanset(_orderedsetmixin):
 
     def isdescending(self):
         return self._start >= self._end
 
     def filter(self, l):
-        if self._start <= self._end:
-            return orderedlazyset(self, l)
-        else:
-            return orderedlazyset(self, l, ascending=False)
+        return orderedlazyset(self, l, ascending=self.isascending())
 
 # tell hggettext to extract docstrings from these functions:
 i18nfunctions = symbols.values()