Patchwork [7,of,8,STABLE] revset: also inline spanset._contained in __len__

login
register
mail settings
Submitter Pierre-Yves David
Date April 29, 2014, 12:48 a.m.
Message ID <00d62213d5785c5875d2.1398732514@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/4451/
State Accepted
Commit e2031c8ca4f8939a21fea454cb64b7a2744d9c8d
Headers show

Comments

Pierre-Yves David - April 29, 2014, 12:48 a.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1398474007 25200
#      Fri Apr 25 18:00:07 2014 -0700
# Branch stable
# Node ID 00d62213d5785c5875d2251d3cde737b994ca1c6
# Parent  881523ca83343eb7e613cb254b46195b8a3261c0
revset: also inline spanset._contained in __len__

For consistency with what happen in `__contains__`, we inline the range test
into `__len__` too.
Durham Goode - April 29, 2014, 2:27 a.m.
On 4/28/14, 5:48 PM, "pierre-yves.david@ens-lyon.org"
<pierre-yves.david@ens-lyon.org> wrote:

># HG changeset patch
># User Pierre-Yves David <pierre-yves.david@fb.com>
># Date 1398474007 25200
>#      Fri Apr 25 18:00:07 2014 -0700
># Branch stable
># Node ID 00d62213d5785c5875d2251d3cde737b994ca1c6
># Parent  881523ca83343eb7e613cb254b46195b8a3261c0
>revset: also inline spanset._contained in __len__
>
>For consistency with what happen in `__contains__`, we inline the range
>test
>into `__len__` too.
>
>diff --git a/mercurial/revset.py b/mercurial/revset.py
>--- a/mercurial/revset.py
>+++ b/mercurial/revset.py
>@@ -2819,12 +2819,14 @@ class spanset(_orderedsetmixin):
>     def __len__(self):
>         if not self._hiddenrevs:
>             return abs(self._end - self._start)
>         else:
>             count = 0
>+            start = self._start
>+            end = self._end
>             for rev in self._hiddenrevs:
>-                if self._contained(rev):
>+                if (end < rev <= start) or (start <= rev and rev < end):

Did you mean to leave the Œand¹ in there instead of collapsing it into a
single a <= b < c like the other patches?

>                     count += 1
>             return abs(self._end - self._start) - count
> 
>     def __getitem__(self, x):
>         # Basic implementation to be changed in future patches.
>_______________________________________________
>Mercurial-devel mailing list
>Mercurial-devel@selenic.com
>http://selenic.com/mailman/listinfo/mercurial-devel
>

Patch

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -2819,12 +2819,14 @@  class spanset(_orderedsetmixin):
     def __len__(self):
         if not self._hiddenrevs:
             return abs(self._end - self._start)
         else:
             count = 0
+            start = self._start
+            end = self._end
             for rev in self._hiddenrevs:
-                if self._contained(rev):
+                if (end < rev <= start) or (start <= rev and rev < end):
                     count += 1
             return abs(self._end - self._start) - count
 
     def __getitem__(self, x):
         # Basic implementation to be changed in future patches.