diff options
author | Björn Gustavsson <bjorn@erlang.org> | 2022-10-30 05:24:23 +0100 |
---|---|---|
committer | Björn Gustavsson <bjorn@erlang.org> | 2023-02-02 06:06:26 +0100 |
commit | a3294534f5b08523b25101ab402c80378fdb1ea0 (patch) | |
tree | 97d57494cc61bcb4521db7e0cbe44b64231edb74 | |
parent | 7bc70bd5904c046c878b3c101555ff13dee12437 (diff) | |
download | erlang-a3294534f5b08523b25101ab402c80378fdb1ea0.tar.gz |
Use modern ETS functions
-rw-r--r-- | lib/dialyzer/src/dialyzer_callgraph.erl | 10 | ||||
-rw-r--r-- | lib/dialyzer/src/dialyzer_codeserver.erl | 27 | ||||
-rw-r--r-- | lib/dialyzer/src/dialyzer_coordinator.erl | 27 |
3 files changed, 27 insertions, 37 deletions
diff --git a/lib/dialyzer/src/dialyzer_callgraph.erl b/lib/dialyzer/src/dialyzer_callgraph.erl index a005360d64..792c4d6911 100644 --- a/lib/dialyzer/src/dialyzer_callgraph.erl +++ b/lib/dialyzer/src/dialyzer_callgraph.erl @@ -337,15 +337,15 @@ module_postorder_from_funs(Funs, #callgraph{digraph = DG, digraph_delete(SubGraph), {PO, CG#callgraph{active_digraph = Active}}. +%% We KNOW that `error` is not a valid value in the table. ets_lookup_dict(Key, Table) -> - try ets:lookup_element(Table, Key, 2) of - Val -> {ok, Val} - catch - _:_ -> error + case ets:lookup_element(Table, Key, 2, error) of + error -> error; + Val -> {ok, Val} end. ets_lookup_set(Key, Table) -> - ets:lookup(Table, Key) =/= []. + ets:member(Table, Key). %%---------------------------------------------------------------------- %% Core code diff --git a/lib/dialyzer/src/dialyzer_codeserver.erl b/lib/dialyzer/src/dialyzer_codeserver.erl index 9b8a165dd0..ee1d3d57e3 100644 --- a/lib/dialyzer/src/dialyzer_codeserver.erl +++ b/lib/dialyzer/src/dialyzer_codeserver.erl @@ -96,11 +96,11 @@ %%-------------------------------------------------------------------- +%% We KNOW that `error` is not a valid value in the table. ets_dict_find(Key, Table) -> - try ets:lookup_element(Table, Key, 2) of - Val -> {ok, Val} - catch - _:_ -> error + case ets:lookup_element(Table, Key, 2, error) of + error -> error; + Val -> {ok, Val} end. ets_map_store(Key, Element, Table) -> @@ -112,7 +112,7 @@ ets_dict_to_dict(Table) -> ets:foldl(Fold, dict:new(), Table). ets_set_is_element(Key, Table) -> - ets:lookup(Table, Key) =/= []. + ets:member(Table, Key). ets_set_insert_set(Set, Table) -> ets_set_insert_list(sets:to_list(Set), Table). @@ -266,10 +266,7 @@ set_next_core_label(NCL, CS) -> -spec lookup_mod_records(atom(), codeserver()) -> types(). lookup_mod_records(Mod, #codeserver{records = RecDict}) when is_atom(Mod) -> - case ets_dict_find(Mod, RecDict) of - error -> maps:new(); - {ok, Map} -> Map - end. + ets:lookup_element(RecDict, Mod, 2, #{}). -spec get_records_table(codeserver()) -> map_ets(). @@ -298,10 +295,7 @@ get_temp_records_table(#codeserver{temp_records = TempRecDict}) -> -spec lookup_temp_mod_records(module(), codeserver()) -> types(). lookup_temp_mod_records(Mod, #codeserver{temp_records = TempRecDict}) -> - case ets_dict_find(Mod, TempRecDict) of - error -> maps:new(); - {ok, Map} -> Map - end. + ets:lookup_element(TempRecDict, Mod, 2, #{}). -spec finalize_records(codeserver()) -> codeserver(). @@ -320,11 +314,8 @@ finalize_records(#codeserver{temp_records = TmpRecords, lookup_mod_contracts(Mod, #codeserver{contracts = ContDict}) when is_atom(Mod) -> - case ets_dict_find(Mod, ContDict) of - error -> maps:new(); - {ok, Keys} -> - maps:from_list([get_file_contract(Key, ContDict)|| Key <- Keys]) - end. + Keys = ets:lookup_element(ContDict, Mod, 2, []), + maps:from_list([get_file_contract(Key, ContDict) || Key <- Keys]). get_file_contract(Key, ContDict) -> {Key, ets:lookup_element(ContDict, Key, 2)}. diff --git a/lib/dialyzer/src/dialyzer_coordinator.erl b/lib/dialyzer/src/dialyzer_coordinator.erl index 44450de048..085c4e938c 100644 --- a/lib/dialyzer/src/dialyzer_coordinator.erl +++ b/lib/dialyzer/src/dialyzer_coordinator.erl @@ -1,3 +1,4 @@ +%% -*- erlang-indent-level: 2 -*- %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. @@ -135,22 +136,20 @@ parallel_job(Mode, Jobs, InitData, Timing) -> %% Helper for 'sigtype' and 'dataflow' workers. wait_for_success_typings(Labels, {_Collector, _Regulator, JobLabelsToPid}) -> - F = - fun(JobLabel) -> - %% The jobs that job depends on have always been started. - try ets:lookup_element(JobLabelsToPid, JobLabel, 2) of - Pid when is_pid(Pid) -> - Ref = erlang:monitor(process, Pid), - receive - {'DOWN', Ref, process, Pid, _Info} -> + F = fun(JobLabel) -> + %% The jobs that job depends on have always been started. + case ets:lookup_element(JobLabelsToPid, JobLabel, 2, ok) of + Pid when is_pid(Pid) -> + Ref = erlang:monitor(process, Pid), + receive + {'DOWN', Ref, process, Pid, _Info} -> + ok + end; + ok -> + %% Already finished. ok end - catch - _:_ -> - %% Already finished. - ok - end - end, + end, lists:foreach(F, Labels). |