diff options
author | Anders Svensson <[email protected]> | 2017-04-28 23:18:20 +0200 |
---|---|---|
committer | Anders Svensson <[email protected]> | 2017-06-13 13:50:06 +0200 |
commit | 494659c32e042937b040f2579a46ec69980ded3a (patch) | |
tree | bb7c9c06818f842a091e0ea34e32ce1e57db1354 /lib | |
parent | 4bfccba1943a21b1f723607f5b8e25773e48d98d (diff) | |
download | otp-494659c32e042937b040f2579a46ec69980ded3a.tar.gz otp-494659c32e042937b040f2579a46ec69980ded3a.tar.bz2 otp-494659c32e042937b040f2579a46ec69980ded3a.zip |
Avoid recreating records
As in the parent commit, recreating the options record is relatively
costly.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/diameter/src/base/diameter_traffic.erl | 39 |
1 files changed, 24 insertions, 15 deletions
diff --git a/lib/diameter/src/base/diameter_traffic.erl b/lib/diameter/src/base/diameter_traffic.erl index 72fb92dcf9..938a6e7af3 100644 --- a/lib/diameter/src/base/diameter_traffic.erl +++ b/lib/diameter/src/base/diameter_traffic.erl @@ -1261,27 +1261,36 @@ send_R(SvcName, AppOrAlias, Msg, CallOpts, Caller) -> %% make_options/1 make_options(Options) -> - lists:foldl(fun mo/2, #options{}, Options). + make_opts(Options, false, [], none, 5000). -mo({timeout, T}, Rec) - when is_integer(T), 0 =< T -> - Rec#options{timeout = T}; +%% Do our own recursion since this is faster than a lists:foldl/3 +%% setting elements in an #options{} accumulator. -mo({filter, F}, #options{filter = none} = Rec) -> - Rec#options{filter = F}; -mo({filter, F}, #options{filter = {all, Fs}} = Rec) -> - Rec#options{filter = {all, [F | Fs]}}; -mo({filter, F}, #options{filter = F0} = Rec) -> - Rec#options{filter = {all, [F0, F]}}; +make_opts([], Detach, Extra, Filter, Tmo) -> + #options{detach = Detach, + extra = Extra, + filter = Filter, + timeout = Tmo}; -mo({extra, L}, #options{extra = X} = Rec) +make_opts([{timeout, Tmo} | Rest], Detach, Extra, Filter, _) + when is_integer(Tmo), 0 =< Tmo -> + make_opts(Rest, Detach, Extra, Filter, Tmo); + +make_opts([{filter, F} | Rest], Detach, Extra, none, Tmo) -> + make_opts(Rest, Detach, Extra, F, Tmo); +make_opts([{filter, F} | Rest], Detach, Extra, {all, Fs}, Tmo) -> + make_opts(Rest, Detach, Extra, {all, [F|Fs]}, Tmo); +make_opts([{filter, F} | Rest], Detach, Extra, F0, Tmo) -> + make_opts(Rest, Detach, Extra, {all, [F0, F]}, Tmo); + +make_opts([{extra, L} | Rest], Detach, Extra, Filter, Tmo) when is_list(L) -> - Rec#options{extra = X ++ L}; + make_opts(Rest, Detach, Extra ++ L, Filter, Tmo); -mo(detach, Rec) -> - Rec#options{detach = true}; +make_opts([detach | Rest], _, Extra, Filter, Tmo) -> + make_opts(Rest, true, Extra, Filter, Tmo); -mo(T, _) -> +make_opts([T | _], _, _, _, _) -> ?ERROR({invalid_option, T}). %% --------------------------------------------------------------------------- |