Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:Ledest:erlang:24
erlang
5221-Use-modern-ETS-functions.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 5221-Use-modern-ETS-functions.patch of Package erlang
From a3294534f5b08523b25101ab402c80378fdb1ea0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= <bjorn@erlang.org> Date: Sun, 30 Oct 2022 05:24:23 +0100 Subject: [PATCH 1/3] Use modern ETS functions --- lib/dialyzer/src/dialyzer_callgraph.erl | 10 ++++----- lib/dialyzer/src/dialyzer_codeserver.erl | 27 ++++++++--------------- 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 @@ -157,15 +157,14 @@ get_next_label(EstimatedSize, {Collector, _Regulator, _SCCtoPid}) -> wait_for_success_typings(SCCs, {_Collector, _Regulator, SCCtoPid}) -> F = fun(SCC) -> %% The SCCs that SCC depends on have always been started. - try ets:lookup_element(SCCtoPid, SCC, 2) of + case ets:lookup_element(SCCtoPid, SCC, 2, ok) of Pid when is_pid(Pid) -> Ref = erlang:monitor(process, Pid), receive {'DOWN', Ref, process, Pid, _Info} -> ok - end - catch - _:_ -> + end; + ok -> %% Already finished. ok end -- 2.35.3
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor