Skip to content

Commit

Permalink
asn1: Use zip comprehensions
Browse files Browse the repository at this point in the history
  • Loading branch information
bjorng committed Oct 4, 2024
1 parent 258a76d commit 57a2883
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
7 changes: 4 additions & 3 deletions lib/asn1/src/asn1ct_check.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2294,9 +2294,10 @@ use_maps(#state{options=Opts}) ->
lists:member(maps, Opts).

create_map_value(Components, ListOfVals) ->
Zipped = lists:zip(Components, ListOfVals),
#{Name => V || {#'ComponentType'{name=Name},V} <- Zipped,
V =/= asn1_NOVALUE}.
#{Name => V ||
#'ComponentType'{name=Name} <- Components &&
V <- ListOfVals,
V =/= asn1_NOVALUE}.

normalize_seq_or_set(SorS, S,
[{#seqtag{val=Cname},V}|Vs],
Expand Down
11 changes: 6 additions & 5 deletions lib/asn1/src/asn1ct_constructed_ber_bin_v2.erl
Original file line number Diff line number Diff line change
Expand Up @@ -171,17 +171,18 @@ enc_match_input(#gen{pack=record}, ValName, CompList) ->
enc_match_input(#gen{pack=map}, ValName, CompList) ->
Len = length(CompList),
Vars = [lists:concat(["Cindex",N]) || N <- lists:seq(1, Len)],
Zipped = lists:zip(CompList, Vars),
M = [[{asis,Name},":=",Var] ||
{#'ComponentType'{prop=mandatory,name=Name},Var} <- Zipped],
#'ComponentType'{prop=mandatory,name=Name} <- CompList &&
Var <- Vars],
case M of
[] ->
ok;
[_|_] ->
emit(["#{",lists:join(",", M),"} = ",ValName,com,nl])
end,
Os0 = [{Name,Var} ||
{#'ComponentType'{prop=Prop,name=Name},Var} <- Zipped,
#'ComponentType'{prop=Prop,name=Name} <- CompList &&
Var <- Vars,
Prop =/= mandatory],
F = fun({Name,Var}) ->
[Var," = case ",ValName," of\n"
Expand Down Expand Up @@ -316,8 +317,8 @@ dec_external(#gen{pack=map}, _RecordName) ->
Vars = asn1ct_name:all(term),
Names = ['direct-reference','indirect-reference',
'data-value-descriptor',encoding],
Zipped = lists:zip(Names, Vars),
MapInit = lists:join(",", [["'",N,"'=>",{var,V}] || {N,V} <- Zipped]),
MapInit = lists:join(",", [["'",N,"'=>",{var,V}] ||
N <- Names && V <- Vars]),
emit(["OldFormat = #{",MapInit,"}",com,nl,
"ASN11994Format =",nl,
{call,ext,transform_to_EXTERNAL1994_maps,
Expand Down
4 changes: 2 additions & 2 deletions lib/asn1/src/asn1ct_constructed_per.erl
Original file line number Diff line number Diff line change
Expand Up @@ -455,8 +455,8 @@ dec_external(#gen{pack=map}, _Typename) ->
Vars = asn1ct_name:all(term),
Names = ['direct-reference','indirect-reference',
'data-value-descriptor',encoding],
Zipped = lists:zip(Names, Vars),
MapInit = lists:join(",", [["'",N,"'=>",{var,V}] || {N,V} <- Zipped]),
MapInit = lists:join(",", [["'",N,"'=>",{var,V}] ||
N <- Names && V <- Vars]),
emit(["OldFormat = #{",MapInit,"}",com,nl,
"ASN11994Format =",nl,
{call,ext,transform_to_EXTERNAL1994_maps,
Expand Down

0 comments on commit 57a2883

Please sign in to comment.