[PATCH 1 of 2 py3 V2] dirstate: use next(iter) instead of iter.next

Pulkit Goyal 7895pulkit at gmail.com
Thu Mar 16 19:57:52 EDT 2017


On Fri, Mar 17, 2017 at 3:17 AM, Martin von Zweigbergk <
martinvonz at google.com> wrote:

> On Thu, Mar 16, 2017 at 2:24 PM, Pulkit Goyal <7895pulkit at gmail.com>
> wrote:
> > # HG changeset patch
> > # User Pulkit Goyal <7895pulkit at gmail.com>
> > # Date 1489634873 -19800
> > #      Thu Mar 16 08:57:53 2017 +0530
> > # Node ID c894bad6625973565b21f556896527141f123dd5
> > # Parent  a5bad127128d8f60060be53d161acfa7a32a17d5
> > dirstate: use next(iter) instead of iter.next
> >
> > In Python 3 world, iter.next() is renamed to iter.__next__(). But
> next(iter)
> > has the same behaviour. So let's replace iter.next() with next(iter).
> >
> > diff -r a5bad127128d -r c894bad66259 mercurial/dirstate.py
> > --- a/mercurial/dirstate.py     Wed Mar 15 15:48:57 2017 -0700
> > +++ b/mercurial/dirstate.py     Thu Mar 16 08:57:53 2017 +0530
> > @@ -1115,9 +1115,8 @@
> >              else:
> >                  # We may not have walked the full directory tree above,
> >                  # so stat and check everything we missed.
> > -                nf = iter(visit).next
> >                  for st in util.statfiles([join(i) for i in visit]):
> > -                    results[nf()] = st
> > +                    results[next(iter(visit))] = st
>
> Won't "next(iter(visit))" get the first element of "visit" every time?​


> Also, since we can no longer cache the .next function itself, and it
> seemed like the old version tried to care about that optimization,
> does this make a noticeable difference? Can you try to figure out
> under what circumstances nf() (in the old version) gets called very
> many times and see if you can measure a difference between the old
> version and the new version? Thanks.
>

​This one is breaking the tests (sorry for not checking before sending).

I guess we need to switch to the V1 of this patch.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.mercurial-scm.org/pipermail/mercurial-devel/attachments/20170317/f6043d1b/attachment.html>


More information about the Mercurial-devel mailing list