diff options
author | Björn-Egil Dahlberg <[email protected]> | 2014-02-26 17:46:57 +0100 |
---|---|---|
committer | Björn-Egil Dahlberg <[email protected]> | 2014-03-14 17:07:56 +0100 |
commit | ea699f3510b464d6b65b30342f2ddd5912e127a7 (patch) | |
tree | 1c42b3bb4d0745684b80e75d59a7c14e3704c908 /lib/compiler/src/cerl.erl | |
parent | 237264bc018b0cc17afeac5d3f6030073f314f9d (diff) | |
download | otp-ea699f3510b464d6b65b30342f2ddd5912e127a7.tar.gz otp-ea699f3510b464d6b65b30342f2ddd5912e127a7.tar.bz2 otp-ea699f3510b464d6b65b30342f2ddd5912e127a7.zip |
compiler: Create literal Maps in creation if possible
Diffstat (limited to 'lib/compiler/src/cerl.erl')
-rw-r--r-- | lib/compiler/src/cerl.erl | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/lib/compiler/src/cerl.erl b/lib/compiler/src/cerl.erl index 3c121f3b04..744ebc7aca 100644 --- a/lib/compiler/src/cerl.erl +++ b/lib/compiler/src/cerl.erl @@ -126,7 +126,7 @@ map_es/1, map_val/1, update_c_map/3, - ann_c_map/3, + ann_c_map/2, ann_c_map/3, map_pair_op/1,map_pair_key/1,map_pair_val/1, update_c_map_pair/4, ann_c_map_pair/4 @@ -1584,8 +1584,24 @@ map_es(#c_map{es = Es}) -> map_val(#c_map{var = M}) -> M. +ann_c_map(As,Es) -> + ann_c_map(As, #c_literal{val=[]}, Es). + +ann_c_map(As,#c_literal{val=[]}=M,Es) -> + Pairs = [[K,V]||#c_map_pair{key=K,val=V}<-Es], + IsLit = lists:foldl(fun(Pair,Res) -> + Res andalso is_lit_list(Pair) + end, true, Pairs), + Fun = fun(Pair) -> [K,V] = lit_list_vals(Pair), {K,V} end, + case IsLit of + false -> + #c_map{var=M, es=Es, anno=As }; + true -> + #c_literal{anno=As, val=maps:from_list(lists:map(Fun, Pairs))} + end; ann_c_map(As,M,Es) -> - #c_map{var=M,es = Es, anno = As }. + #c_map{var=M, es = Es, anno = As }. + update_c_map(Old,M,Es) -> #c_map{var=M, es = Es, anno = get_ann(Old)}. |