aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAnders Svensson <[email protected]>2017-04-17 13:21:32 +0200
committerAnders Svensson <[email protected]>2017-06-12 16:13:52 +0200
commita75a449b831b857dc3d2fc6f4ba872a3b6563ee5 (patch)
tree727ba5dbfb4ee9be2495b9fdf702ef3df1af1468 /lib
parentf1a78f768414e97d30e72b1530475f2893fc75c5 (diff)
downloadotp-a75a449b831b857dc3d2fc6f4ba872a3b6563ee5.tar.gz
otp-a75a449b831b857dc3d2fc6f4ba872a3b6563ee5.tar.bz2
otp-a75a449b831b857dc3d2fc6f4ba872a3b6563ee5.zip
Don't create intermediate terms unnecessarily during encode
Diffstat (limited to 'lib')
-rw-r--r--lib/diameter/src/base/diameter_codec.erl22
1 files changed, 12 insertions, 10 deletions
diff --git a/lib/diameter/src/base/diameter_codec.erl b/lib/diameter/src/base/diameter_codec.erl
index 0d107bf8da..9a7a7ad945 100644
--- a/lib/diameter/src/base/diameter_codec.erl
+++ b/lib/diameter/src/base/diameter_codec.erl
@@ -40,7 +40,8 @@
-include("diameter_internal.hrl").
-define(PAD(Len), ((4 - (Len rem 4)) rem 4)).
--define(BIT(B), (if B -> 1; true -> 0 end)).
+-define(BIT(B,I), (if B -> I; true -> 0 end)).
+-define(BIT(B), ?BIT(B,1)).
-define(FLAGS(R,P,E,T), ?BIT(R):1, ?BIT(P):1, ?BIT(E):1, ?BIT(T):1, 0:4).
-define(FLAG(B,D), (if is_boolean(B) -> B; true -> 0 /= (D) end)).
@@ -704,26 +705,27 @@ pack_avp(#diameter_avp{code = Code,
is_mandatory = M,
need_encryption = P,
data = Data}) ->
- Flags = lists:foldl(fun flag_avp/2, 0, [{V /= undefined, 2#10000000},
- {M, 2#01000000},
- {P, 2#00100000}]),
- pack_avp({Code, Flags, V}, Data).
+ Flags = ?BIT(V /= undefined, 2#10000000)
+ bor ?BIT(M, 2#01000000)
+ bor ?BIT(P, 2#00100000),
+
+ pack_avp(Code, Flags, V, Data).
header_length(<<_:32, 1:1, _/bitstring>>) ->
12;
header_length(_) ->
8.
-flag_avp({true, B}, F) ->
- F bor B;
-flag_avp({false, _}, F) ->
- F.
-
%%% ---------------------------------------------------------------------------
%%% # pack_avp/2
%%% ---------------------------------------------------------------------------
pack_avp({Code, Flags, VendorId}, Data) ->
+ pack_avp(Code, Flags, VendorId, Data).
+
+%% pack_avp/4
+
+pack_avp(Code, Flags, VendorId, Data) ->
Sz = iolist_size(Data),
pack_avp(Code, Flags, Sz, VendorId, Data, ?PAD(Sz)).
%% Padding is not included in the length field, as mandated by the RFC.