diff options
author | Hans Bolinder <[email protected]> | 2017-01-25 12:51:34 +0100 |
---|---|---|
committer | Hans Bolinder <[email protected]> | 2017-02-01 09:14:57 +0100 |
commit | 7db0ed6161a68ab7608abe98947ae209da31ae33 (patch) | |
tree | 35ca8995f75da262854e5c2cfe94ee7ffd33015a | |
parent | 21d21786abdaae2ae0a601baf5102412399d7af6 (diff) | |
download | otp-7db0ed6161a68ab7608abe98947ae209da31ae33.tar.gz otp-7db0ed6161a68ab7608abe98947ae209da31ae33.tar.bz2 otp-7db0ed6161a68ab7608abe98947ae209da31ae33.zip |
dialyzer: Optimize collection of variables
-rw-r--r-- | lib/hipe/cerl/erl_types.erl | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/lib/hipe/cerl/erl_types.erl b/lib/hipe/cerl/erl_types.erl index 7edfbf65df..10e97ff54d 100644 --- a/lib/hipe/cerl/erl_types.erl +++ b/lib/hipe/cerl/erl_types.erl @@ -2243,16 +2243,21 @@ t_has_var_list([]) -> false. -spec t_collect_vars(erl_type()) -> [erl_type()]. t_collect_vars(T) -> - t_collect_vars(T, []). + Vs = t_collect_vars(T, maps:new()), + [V || {V, _} <- maps:to_list(Vs)]. --spec t_collect_vars(erl_type(), [erl_type()]) -> [erl_type()]. +-type ctab() :: #{erl_type() => 'any'}. + +-spec t_collect_vars(erl_type(), ctab()) -> ctab(). t_collect_vars(?var(_) = Var, Acc) -> - ordsets:add_element(Var, Acc); + maps:put(Var, any, Acc); t_collect_vars(?function(Domain, Range), Acc) -> - ordsets:union(t_collect_vars(Domain, Acc), t_collect_vars(Range, [])); + Acc1 = t_collect_vars(Domain, Acc), + t_collect_vars(Range, Acc1); t_collect_vars(?list(Contents, Termination, _), Acc) -> - ordsets:union(t_collect_vars(Contents, Acc), t_collect_vars(Termination, [])); + Acc1 = t_collect_vars(Contents, Acc), + t_collect_vars(Termination, Acc1); t_collect_vars(?product(Types), Acc) -> t_collect_vars_list(Types, Acc); t_collect_vars(?tuple(?any, ?any, ?any), Acc) -> |