[Mesa-dev] [PATCH 16/26] python: Explicitly use lists
Dylan Baker
dylan at pnwbakers.com
Thu Jul 5 16:31:30 UTC 2018
Quoting Mathieu Bridon (2018-07-05 06:17:47)
> On Python 2, the builtin functions filter() and zip() would return
> lists.
>
> On Python 3, they return iterators.
>
> Since we want to use those objects in contexts where we need lists, we
> need to explicitly turn them into lists.
>
> This makes the code compatible with both Python 2 and Python 3.
>
> Signed-off-by: Mathieu Bridon <bochecha at daitauha.fr>
> ---
> src/compiler/nir/nir_opt_algebraic.py | 2 +-
> src/mesa/main/get_hash_generator.py | 4 ++--
> 2 files changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py
> index 5e07d662b0..7b2ba56990 100644
> --- a/src/compiler/nir/nir_opt_algebraic.py
> +++ b/src/compiler/nir/nir_opt_algebraic.py
> @@ -633,7 +633,7 @@ optimizations = [
>
> invert = OrderedDict([('feq', 'fne'), ('fne', 'feq'), ('fge', 'flt'), ('flt', 'fge')])
>
> -for left, right in list(itertools.combinations(invert.keys(), 2)) + zip(invert.keys(), invert.keys()):
> +for left, right in list(itertools.combinations(invert.keys(), 2)) + list(zip(invert.keys(), invert.keys())):
Isn't this just a really expenisve re-implementation of:
itertools.combinations_with_replacement(invert.keys(), 2)
There's really no reason to make this concrete either, so lets not.
This will change the order of the output slightly, but I think that's okay.
> optimizations.append((('inot', ('ior(is_used_once)', (left, a, b), (right, c, d))),
> ('iand', (invert[left], a, b), (invert[right], c, d))))
> optimizations.append((('inot', ('iand(is_used_once)', (left, a, b), (right, c, d))),
> diff --git a/src/mesa/main/get_hash_generator.py b/src/mesa/main/get_hash_generator.py
> index facdccd8a5..37dae45e0b 100644
> --- a/src/mesa/main/get_hash_generator.py
> +++ b/src/mesa/main/get_hash_generator.py
> @@ -117,8 +117,8 @@ def print_tables(tables):
> def merge_tables(tables):
> merged_tables = []
> for api, indices in sorted(tables.items()):
> - matching_table = filter(lambda mt:mt["indices"] == indices,
> - merged_tables)
> + matching_table = list(filter(lambda mt:mt["indices"] == indices,
> + merged_tables))
how about:
matching_table = [m for m in merged_tables if m["indicies" == indicies"]
since that works in both, is more common python, and avoids the extra function
call and the lambda.
> if matching_table:
> matching_table[0]["apis"].append(api)
> else:
> --
> 2.17.1
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 228 bytes
Desc: signature
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20180705/bc665c8f/attachment.sig>
More information about the mesa-dev
mailing list