summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Sackman <matthew@rabbitmq.com>2010-10-27 15:09:10 +0100
committerMatthew Sackman <matthew@rabbitmq.com>2010-10-27 15:09:10 +0100
commit1b2246324499f428d6dfb160a59feece114e9035 (patch)
treee25fca53ff866202c95fdace517ec24b51ae1363
parente16b59f63170160c1553401d2c9726a4efe3ea78 (diff)
downloadrabbitmq-server-git-1b2246324499f428d6dfb160a59feece114e9035.tar.gz
Even more beautiful
-rw-r--r--src/rabbit.erl13
-rw-r--r--src/rabbit_misc.erl45
2 files changed, 27 insertions, 31 deletions
diff --git a/src/rabbit.erl b/src/rabbit.erl
index 506de77b31..346a7a804a 100644
--- a/src/rabbit.erl
+++ b/src/rabbit.erl
@@ -308,12 +308,13 @@ vertices(_Module, Steps) ->
[{StepName, {StepName, Atts}} || {StepName, Atts} <- Steps].
edges(_Module, Steps) ->
- lists:flatten(
- [[[{StepName, PrecedingStepName}
- || {requires, PrecedingStepName} <- Atts],
- [{SucceedingStepName, StepName}
- || {enables, SucceedingStepName} <- Atts]]
- || {StepName, Atts} <- Steps]).
+ [case Key of
+ requires -> {StepName, OtherStep};
+ enables -> {OtherStep, StepName}
+ end || {StepName, Atts} <- Steps,
+ Key <- [requires, enables],
+ {Key1, OtherStep} <- Atts,
+ Key1 =:= Key].
graph_build_error({vertex, duplicate, StepName}) ->
boot_error("Duplicate boot step name: ~w~n", [StepName]);
diff --git a/src/rabbit_misc.erl b/src/rabbit_misc.erl
index a27edebc0d..810308921d 100644
--- a/src/rabbit_misc.erl
+++ b/src/rabbit_misc.erl
@@ -737,36 +737,31 @@ module_attributes(Module) ->
end.
all_module_attributes(Name) ->
- AllApps = [App || {App, _, _} <- application:loaded_applications()],
- Modules = lists:usort(
- lists:append([Modules
- || {ok, Modules} <-
- [application:get_key(App, modules)
- || App <- AllApps]])),
+ Modules =
+ lists:usort(
+ lists:append(
+ [Modules || {App, _, _} <- application:loaded_applications(),
+ {ok, Modules} <- [application:get_key(App, modules)]])),
lists:foldl(
fun (Module, Acc) ->
- case lists:append(
- [Atts || {N, Atts} <- module_attributes(Module),
- N =:= Name]) of
+ case lists:append([Atts || {N, Atts} <- module_attributes(Module),
+ N =:= Name]) of
[] -> Acc;
- Atts -> dict:update(Module, fun (Old) -> Atts ++ Old end,
- Atts, Acc)
+ Atts -> [{Module, Atts} | Acc]
end
- end, dict:new(), Modules).
+ end, [], Modules).
+
build_acyclic_graph(VertexFun, EdgeFun, ErrorFun, Graph) ->
G = digraph:new([acyclic]),
- dict:fold(
- fun (Module, Values, _Acc) ->
- [case digraph:vertex(G, Vertex) of
- false -> digraph:add_vertex(G, Vertex, Label);
- _ -> ErrorFun({vertex, duplicate, Vertex})
- end || {Vertex, Label} <- VertexFun(Module, Values)]
- end, ok, Graph),
- dict:fold(fun (Module, Values, _Acc) ->
- [case digraph:add_edge(G, From, To) of
- {error, E} -> ErrorFun({edge, E, From, To});
- _ -> ok
- end || {From, To} <- EdgeFun(Module, Values)]
- end, ok, Graph),
+ [ case digraph:vertex(G, Vertex) of
+ false -> digraph:add_vertex(G, Vertex, Label);
+ _ -> ErrorFun({vertex, duplicate, Vertex})
+ end || {Module, Atts} <- Graph,
+ {Vertex, Label} <- VertexFun(Module, Atts) ],
+ [ case digraph:add_edge(G, From, To) of
+ {error, E} -> ErrorFun({edge, E, From, To});
+ _ -> ok
+ end || {Module, Atts} <- Graph,
+ {From, To} <- EdgeFun(Module, Atts) ],
G.