aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnders Svensson <[email protected]>2017-04-22 12:43:33 +0200
committerAnders Svensson <[email protected]>2017-06-12 16:13:52 +0200
commit6e753c9861effb4ae820d7b1ad20fdb66dca34f6 (patch)
tree601bd569bdf061101ad43e3698934dc232bb3631
parent05a9572161fde1054946ca17386890b0c7138500 (diff)
downloadotp-6e753c9861effb4ae820d7b1ad20fdb66dca34f6.tar.gz
otp-6e753c9861effb4ae820d7b1ad20fdb66dca34f6.tar.bz2
otp-6e753c9861effb4ae820d7b1ad20fdb66dca34f6.zip
Use avp_arity/1 when detecting missing AVPs
Recursing over the entire list of arities and values is faster than retrieving them one at a time.
-rw-r--r--lib/diameter/include/diameter_gen.hrl32
1 files changed, 24 insertions, 8 deletions
diff --git a/lib/diameter/include/diameter_gen.hrl b/lib/diameter/include/diameter_gen.hrl
index 968cf66ea7..3c59370e73 100644
--- a/lib/diameter/include/diameter_gen.hrl
+++ b/lib/diameter/include/diameter_gen.hrl
@@ -226,17 +226,33 @@ missing(Rec, Name, Failed) ->
end,
maps:new(),
Failed),
- [{5005, empty_avp(F,H)} || {F,T} <- '#get-'(Rec),
- not has_arity(avp_arity(Name, F), T),
- {C,_,V} = H <- [avp_header(F)],
- not maps:is_key({C,V}, Avps)].
+ missing(avp_arity(Name), tl(tuple_to_list(Rec)), Avps, []).
+
+missing([{Name, Arity} | As], [Value | Vs], Avps, Acc) ->
+ missing(As, Vs, Avps, case
+ [H || missing_arity(Arity, Value),
+ {C,_,V} = H <- [avp_header(Name)],
+ not maps:is_key({C,V}, Avps)]
+ of
+ [H] ->
+ [{5005, empty_avp(Name, H)} | Acc];
+ [] ->
+ Acc
+ end);
+
+missing([], [], _, Acc) ->
+ Acc.
%% Maximum arities have already been checked in building the record.
-has_arity({Min, _}, L) ->
- has_prefix(Min, L);
-has_arity(N, V) ->
- N /= 1 orelse V /= undefined.
+missing_arity(1, V) ->
+ V == undefined;
+missing_arity({0, _}, _) ->
+ false;
+missing_arity({1, _}, L) ->
+ [] == L;
+missing_arity({Min, _}, L) ->
+ not has_prefix(Min, L).
%% Compare a non-negative integer and the length of a list without
%% computing the length.