diff options
| author | Tim Watson <watson.timothy@gmail.com> | 2013-11-20 12:24:49 +0000 |
|---|---|---|
| committer | Tim Watson <watson.timothy@gmail.com> | 2013-11-20 12:24:49 +0000 |
| commit | 33cbee5b3799ef2b301cf513f6fef1103d26bc32 (patch) | |
| tree | 286c7dc9aa3bbc8904423e030dc6a67402a83f10 | |
| parent | bc371b7de17216b213ac3ef3638b42d31fcc7b79 (diff) | |
| download | rabbitmq-server-git-33cbee5b3799ef2b301cf513f6fef1103d26bc32.tar.gz | |
Refactor (de-duplicate) module attribute search
| -rw-r--r-- | src/rabbit_misc.erl | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/src/rabbit_misc.erl b/src/rabbit_misc.erl index 3f5bee55d7..26071a8aef 100644 --- a/src/rabbit_misc.erl +++ b/src/rabbit_misc.erl @@ -852,36 +852,37 @@ module_attributes(Module) -> end. all_app_module_attributes(Name) -> - Modules = - lists:usort( - lists:flatten( - [{App, Module} || - {App, _, _} <- application:loaded_applications(), - {ok, Modules} <- [application:get_key(App, modules)], - Module <- Modules])), - lists:foldl( + find_module_attributes( + fun(App, Modules) -> + [{App, Module} || Module <- Modules] + end, fun ({App, Module}, Acc) -> case lists:append([Atts || {N, Atts} <- module_attributes(Module), N =:= Name]) of [] -> Acc; Atts -> [{App, Module, Atts} | Acc] end - end, [], Modules). + end). all_module_attributes(Name) -> - Modules = - lists:usort( - lists:append( - [Modules || {App, _, _} <- application:loaded_applications(), - {ok, Modules} <- [application:get_key(App, modules)]])), - lists:foldl( + find_module_attributes( + fun(_App, Modules) -> Modules end, fun (Module, Acc) -> case lists:append([Atts || {N, Atts} <- module_attributes(Module), N =:= Name]) of [] -> Acc; Atts -> [{Module, Atts} | Acc] end - end, [], Modules). + end). + +find_module_attributes(Generator, Fold) -> + Targets = + lists:usort( + lists:append( + [Generator(App, Modules) || + {App, _, _} <- application:loaded_applications(), + {ok, Modules} <- [application:get_key(App, modules)]])), + lists:foldl(Fold, [], Targets). build_acyclic_graph(VertexFun, EdgeFun, Graph) -> G = digraph:new([acyclic]), |
