D1337: util: add util.clearcachedproperty
indygreg (Gregory Szorc)
phabricator at mercurial-scm.org
Fri Nov 10 00:18:54 EST 2017
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
More information about the Mercurial-devel
mailing list