From 6e753c9861effb4ae820d7b1ad20fdb66dca34f6 Mon Sep 17 00:00:00 2001 From: Anders Svensson Date: Sat, 22 Apr 2017 12:43:33 +0200 Subject: 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. --- lib/diameter/include/diameter_gen.hrl | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) (limited to 'lib') 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. -- cgit v1.2.3