Submitter | phabricator |
---|---|
Date | Nov. 8, 2017, 5:31 p.m. |
Message ID | <differential-rev-PHID-DREV-oms557fv32ffncgzyvrp-req@phab.mercurial-scm.org> |
Download | mbox | patch |
Permalink | /patch/25422/ |
State | Superseded |
Headers | show |
Comments
indygreg accepted this revision. indygreg added inline comments. This revision is now accepted and ready to land. INLINE COMMENTS > util.py:936-937 > + '''clear a cached property value, if one has been set''' > + if prop in obj.__dict__: > + del obj.__dict__[prop] > + This pattern is commonly implemented using a ``try..except KeyError`` around the ``del``. This avoids the double key lookup and I /think/ is faster. But since this is a super small function and won't be called with high frequency (I assume), it shouldn't be a problem. If a loop were so tight that it mattered, execution time would be dominated by Python function call overhead, not the low-level primitives inside the function. REPOSITORY rHG Mercurial REVISION DETAIL https://phab.mercurial-scm.org/D1337 To: mbthomas, #hg-reviewers, indygreg Cc: indygreg, mercurial-devel
Patch
diff --git a/mercurial/util.py b/mercurial/util.py --- a/mercurial/util.py +++ b/mercurial/util.py @@ -931,6 +931,11 @@ # __dict__ assignment required to bypass __setattr__ (eg: repoview) obj.__dict__[self.name] = value +def clearcachedproperty(obj, prop): + '''clear a cached property value, if one has been set''' + if prop in obj.__dict__: + del obj.__dict__[prop] + def pipefilter(s, cmd): '''filter string S through command CMD, returning its output''' p = subprocess.Popen(cmd, shell=True, close_fds=closefds,