[PATCH 04 of 10] py3: pass dict.items() to list() to obtain a list

Augie Fackler raf at durin42.com
Thu Jun 1 14:27:57 UTC 2017


On Thu, Jun 01, 2017 at 03:17:00AM +0530, Pulkit Goyal wrote:
> # HG changeset patch
> # User Pulkit Goyal <7895pulkit at gmail.com>
> # Date 1496259842 -19800
> #      Thu Jun 01 01:14:02 2017 +0530
> # Node ID 66f3c6ec7827f4bc1d28673c0478ca42d60656ed
> # Parent  25718d4a6de987771b43874573e1095c9cfc5ab2
> py3: pass dict.items() to list() to obtain a list
>
> dict.items() returned a list on Python 2 and whereas on Python 3 it returns a
> view object, so we need to pass it into list() to get a list.
>
> diff --git a/mercurial/copies.py b/mercurial/copies.py
> --- a/mercurial/copies.py
> +++ b/mercurial/copies.py
> @@ -419,8 +419,9 @@
>      for f in u2u:
>          _checkcopies(c2, f, m2, m1, base, tca, dirtyc2, limit, data2)
>
> -    copy = dict(data1['copy'].items() + data2['copy'].items())
> -    fullcopy = dict(data1['fullcopy'].items() + data2['fullcopy'].items())
> +    copy = dict(list(data1['copy'].items()) + list(data2['copy'].items()))
> +    fullcopy = dict(list(data1['fullcopy'].items()) +
> +                                        list(data2['fullcopy'].items()))

Hm. I think it'd be more efficient to do:

copy = dict(data1['copy'])
copy.update(data2['copy'])

which avoids actually constructing the lists, and should save on gc
churn. Can you try that?

>
>      if dirtyc1:
>          _combinecopies(data2['incomplete'], data1['incomplete'], copy, diverge,
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


More information about the Mercurial-devel mailing list