priestjim / gen_rpc

A scalable RPC library for Erlang-VM based languages

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Potential unnecessary function arguments guard checking

linearregression opened this issue · comments

call(Node, M, F) when is_atom(Node), is_atom(M), is_atom(F) ->
call(Node, M, F, [], undefined, undefined).
Lots of calls are funneled back to one master call, which already does guard checking. Is there a need to do on upstream?
Example:
gen_rpc_client
call(Node, M, F, A) when is_atom(Node), is_atom(M), is_atom(F), is_list(A) -> call(Node, M, F, A, undefined, undefined).

call(Node, M, F, A, RecvTO) when is_atom(Node), is_atom(M), is_atom(F), is_list(A), ?is_timeout(RecvTO) -> call(Node, M, F, A, RecvTO, undefined).

call(Node, M, F, A, RecvTO, SendTO) when is_atom(Node), is_atom(M), is_atom(F), is_list(A), RecvTO =:= undefined orelse ?is_timeout(RecvTO), SendTO =:= undefined orelse ?is_timeout(SendTO)

I left the guards there to crash the function call in case the call does not meet the guards. Do you think it's confusing and/or affects performance?

Not confusing. They are calling the one at the bottom eventually.
example:
Check is done twice. e.g. is_atom(Node) for the following.
call(Node, M, F, A) when is_atom(Node), is_atom(M), is_atom(F), is_list(A) -> call(Node, M, F, A, undefined, undefined).

I am suggesting that you just need to check at the last call() in the chain.
call(Node, M, F, A, RecvTO, SendTO) when is_atom(Node), is_atom(M), is_atom(F), is_list(A), RecvTO =:= undefined orelse ?is_timeout(RecvTO), SendTO =:= undefined orelse ?is_timeout(SendTO)