[PATCH] revset: cache smartset's min/max

Pierre-Yves David pierre-yves.david at ens-lyon.org
Fri Aug 28 01:12:52 UTC 2015


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at 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.

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


More information about the Mercurial-devel mailing list