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

login
register
mail settings
Submitter Pulkit Goyal
Date March 16, 2017, 9:24 p.m.
Message ID <c894bad6625973565b21.1489699489@pulkit-goyal>
Download mbox | patch
Permalink /patch/19401/
State Changes Requested
Headers show

Comments

Pulkit Goyal - March 16, 2017, 9:24 p.m.
# HG changeset patch
# User Pulkit Goyal <7895pulkit@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).
via Mercurial-devel - March 16, 2017, 9:47 p.m.
On Thu, Mar 16, 2017 at 2:24 PM, Pulkit Goyal <7895pulkit@gmail.com> wrote:
> # HG changeset patch
> # User Pulkit Goyal <7895pulkit@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.

>          return results
>
>      def status(self, match, subrepos, ignored, clean, unknown):
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Patch

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
         return results
 
     def status(self, match, subrepos, ignored, clean, unknown):