Mercurial > public > mercurial-scm > hg
comparison mercurial/revset.py @ 30227:5ee944b9c750 stable
revset: don't cache abstractsmartset min/max invocations infinitely
There was a "leak", apparently introduced in ab66c1dee405. When running:
hg = hglib.open('repo')
while True:
hg.log("max(branch('default'))")
all filteredset instances from branch() would be cached indefinitely by the
@util.cachefunc annotation on the max() implementation.
util.cachefunc seems dangerous as method decorator and is barely used elsewhere
in the code base. Instead, just open code caching by having the min/max
methods replace themselves with a plain lambda returning the result.
author | Mads Kiilerich <madski@unity3d.com> |
---|---|
date | Tue, 25 Oct 2016 18:56:27 +0200 |
parents | b4074417b661 |
children | 318a24b52eeb |
comparison
equal
deleted
inserted
replaced
30226:264f00b3e5f0 | 30227:5ee944b9c750 |
---|---|
2922 | 2922 |
2923 def istopo(self): | 2923 def istopo(self): |
2924 """True if the set will iterate in topographical order""" | 2924 """True if the set will iterate in topographical order""" |
2925 raise NotImplementedError() | 2925 raise NotImplementedError() |
2926 | 2926 |
2927 @util.cachefunc | |
2928 def min(self): | 2927 def min(self): |
2929 """return the minimum element in the set""" | 2928 """return the minimum element in the set""" |
2930 if self.fastasc is not None: | 2929 if self.fastasc is None: |
2931 for r in self.fastasc(): | 2930 v = min(self) |
2932 return r | 2931 else: |
2933 raise ValueError('arg is an empty sequence') | 2932 for v in self.fastasc(): |
2934 return min(self) | 2933 break |
2935 | 2934 else: |
2936 @util.cachefunc | 2935 raise ValueError('arg is an empty sequence') |
2936 self.min = lambda: v | |
2937 return v | |
2938 | |
2937 def max(self): | 2939 def max(self): |
2938 """return the maximum element in the set""" | 2940 """return the maximum element in the set""" |
2939 if self.fastdesc is not None: | 2941 if self.fastdesc is None: |
2940 for r in self.fastdesc(): | 2942 return max(self) |
2941 return r | 2943 else: |
2942 raise ValueError('arg is an empty sequence') | 2944 for v in self.fastdesc(): |
2943 return max(self) | 2945 break |
2946 else: | |
2947 raise ValueError('arg is an empty sequence') | |
2948 self.max = lambda: v | |
2949 return v | |
2944 | 2950 |
2945 def first(self): | 2951 def first(self): |
2946 """return the first element in the set (user iteration perspective) | 2952 """return the first element in the set (user iteration perspective) |
2947 | 2953 |
2948 Return None if the set is empty""" | 2954 Return None if the set is empty""" |