Page MenuHomePhabricator

util: add util.clearcachedproperty
ClosedPublic

Authored by mbthomas on Nov 8 2017, 12:30 PM.

Details

Summary

This utility function allows clearing of the cached value set up
@propertycache, if there is one.

Diff Detail

Repository
rHG Mercurial
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

mbthomas created this revision.Nov 8 2017, 12:30 PM
indygreg accepted this revision.Nov 10 2017, 12:18 AM
indygreg added a subscriber: indygreg.
indygreg added inline comments.
mercurial/util.py
936–937

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.

This revision is now accepted and ready to land.Nov 10 2017, 12:18 AM
durin42 accepted this revision.Nov 10 2017, 5:12 PM
This revision was automatically updated to reflect the committed changes.