summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Radestock <matthias@rabbitmq.com>2013-01-06 00:35:11 +0000
committerMatthias Radestock <matthias@rabbitmq.com>2013-01-06 00:35:11 +0000
commit115369202c1a49b3030e091a545c775149b818da (patch)
tree7ec4f9e5e8eaa270b286f9ae495b2a34a378f490
parent0949f2f599c5183c4beb979b6804936dd29525ce (diff)
downloadrabbitmq-server-115369202c1a49b3030e091a545c775149b818da.tar.gz
common-case optimisations for delegate:invoke[_no_result]
-rw-r--r--src/delegate.erl12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/delegate.erl b/src/delegate.erl
index 9222c34c..96b8ba31 100644
--- a/src/delegate.erl
+++ b/src/delegate.erl
@@ -62,6 +62,13 @@ invoke(Pid, Fun) when is_pid(Pid) ->
erlang:raise(Class, Reason, StackTrace)
end;
+invoke([], _Fun) -> %% optimisation
+ {[], []};
+invoke([Pid], Fun) when node(Pid) =:= node() -> %% optimisation
+ case safe_invoke(Pid, Fun) of
+ {ok, _, Result} -> {[{Pid, Result}], []};
+ {error, _, Error} -> {[], [{Pid, Error}]}
+ end;
invoke(Pids, Fun) when is_list(Pids) ->
{LocalPids, Grouped} = group_pids_by_node(Pids),
%% The use of multi_call is only safe because the timeout is
@@ -90,6 +97,11 @@ invoke_no_result(Pid, Fun) when is_pid(Pid) andalso node(Pid) =:= node() ->
invoke_no_result(Pid, Fun) when is_pid(Pid) ->
invoke_no_result([Pid], Fun);
+invoke_no_result([], _Fun) -> %% optimisation
+ ok;
+invoke_no_result([Pid], Fun) when node(Pid) =:= node() -> %% optimisation
+ safe_invoke(Pid, Fun), %% must not die
+ ok;
invoke_no_result(Pids, Fun) when is_list(Pids) ->
{LocalPids, Grouped} = group_pids_by_node(Pids),
case orddict:fetch_keys(Grouped) of