[PATCH 3 of 4 V3] dirstate: add code to update the non-normal map when it should be
Matt Mackall
mpm at selenic.com
Fri Dec 18 14:24:51 CST 2015
On Thu, 2015-12-17 at 12:49 -0800, Bryan O'Sullivan wrote:
> On Thu, Dec 17, 2015 at 10:24 AM, Laurent Charignon <lcharignon at fb.co
> m>
> wrote:
>
> > + if f in self._nonnormalmap:
> > + del self._nonnormalmap[f]
> >
>
> Pro tip for this kind of code is that it can be written as a more
> efficient
> one-liner.
>
> self._nonnormalmap.pop(f, None)
I can see why someone would think that, but:
$ python -m timeit -s 'd = {}' -c 'if "a" in d: del d["a"]'
10000000 loops, best of 3: 0.0341 usec per loop
$ python -m timeit -s 'd = {}' -c 'd["a"] = 1' 'if "a" in d: del d["a"]'
10000000 loops, best of 3: 0.102 usec per loop
$ python -m timeit -s 'd = {}' -c 'd.pop("a", None)'
10000000 loops, best of 3: 0.106 usec per loop
$ python -m timeit -s 'd = {}' -c 'd["a"]=1; d.pop("a", None)'
10000000 loops, best of 3: 0.162 usec per loop
--
Mathematics is the supreme nostalgia of our time.
More information about the Mercurial-devel
mailing list