Patchwork revset: cache smartset's min/max

login
register
mail settings
Submitter Pierre-Yves David
Date Aug. 28, 2015, 1:12 a.m.
Message ID <b0fb67f6080b742e1a45.1440724372@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/10311/
State Accepted
Headers show

Comments

Pierre-Yves David - Aug. 28, 2015, 1:12 a.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1440723453 25200
#      Thu Aug 27 17:57:33 2015 -0700
# Node ID b0fb67f6080b742e1a45cccc68668bac0b5498c6
# Parent  cf3212174adb57b7699a77e20295e9c8d36d9aa2
revset: cache smartset's min/max

As the content of a smartset never changes, min and max will never change
either.  This will save use time when this function is called multiple time.
This is relevant for issue4782 but does not fix it.
Augie Fackler - Aug. 28, 2015, 5:31 p.m.
On Thu, Aug 27, 2015 at 06:12:52PM -0700, Pierre-Yves David wrote:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david@fb.com>
> # Date 1440723453 25200
> #      Thu Aug 27 17:57:33 2015 -0700
> # Node ID b0fb67f6080b742e1a45cccc68668bac0b5498c6
> # Parent  cf3212174adb57b7699a77e20295e9c8d36d9aa2
> revset: cache smartset's min/max

Queued, thanks.

>
> As the content of a smartset never changes, min and max will never change
> either.  This will save use time when this function is called multiple time.
> This is relevant for issue4782 but does not fix it.
>
> diff --git a/mercurial/revset.py b/mercurial/revset.py
> --- a/mercurial/revset.py
> +++ b/mercurial/revset.py
> @@ -2884,18 +2884,20 @@ class abstractsmartset(object):
>
>      def isdescending(self):
>          """True if the set will iterate in descending order"""
>          raise NotImplementedError()
>
> +    @util.cachefunc
>      def min(self):
>          """return the minimum element in the set"""
>          if self.fastasc is not None:
>              for r in self.fastasc():
>                  return r
>              raise ValueError('arg is an empty sequence')
>          return min(self)
>
> +    @util.cachefunc
>      def max(self):
>          """return the maximum element in the set"""
>          if self.fastdesc is not None:
>              for r in self.fastdesc():
>                  return r
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> https://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
@@ -2884,18 +2884,20 @@  class abstractsmartset(object):
 
     def isdescending(self):
         """True if the set will iterate in descending order"""
         raise NotImplementedError()
 
+    @util.cachefunc
     def min(self):
         """return the minimum element in the set"""
         if self.fastasc is not None:
             for r in self.fastasc():
                 return r
             raise ValueError('arg is an empty sequence')
         return min(self)
 
+    @util.cachefunc
     def max(self):
         """return the maximum element in the set"""
         if self.fastdesc is not None:
             for r in self.fastdesc():
                 return r