diff options
author | Anders Svensson <[email protected]> | 2017-04-17 16:43:19 +0200 |
---|---|---|
committer | Anders Svensson <[email protected]> | 2017-06-12 16:13:52 +0200 |
commit | d5d3d5fa029cd04261921427bb0f64ca0efc7b8c (patch) | |
tree | 53c70f0f6f4f28d8c26d28a1059ad2e67fe1d023 /lib | |
parent | 0dd4fe49665a39a407764823ea3fabbc7bd8935b (diff) | |
download | otp-d5d3d5fa029cd04261921427bb0f64ca0efc7b8c.tar.gz otp-d5d3d5fa029cd04261921427bb0f64ca0efc7b8c.tar.bz2 otp-d5d3d5fa029cd04261921427bb0f64ca0efc7b8c.zip |
Optimize sub binary creation
Diffstat (limited to 'lib')
-rw-r--r-- | lib/diameter/src/base/diameter_codec.erl | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/lib/diameter/src/base/diameter_codec.erl b/lib/diameter/src/base/diameter_codec.erl index 90683e7329..43cc49903d 100644 --- a/lib/diameter/src/base/diameter_codec.erl +++ b/lib/diameter/src/base/diameter_codec.erl @@ -698,15 +698,17 @@ pack_avp(#diameter_avp{code = undefined, data = B}) %% error. The RFC doesn't explicitly say to do this but the %% receiver can't correctly extract this and following AVP's %% without a correct length. On the downside, the header doesn't - %% reveal if the received header has been padded. - Pad = 8*header_length(B) - bit_size(B), - Len = size(<<H:5/binary, _:24, T/binary>> = <<B/binary, 0:Pad>>), - <<H/binary, Len:24, T/binary>>; + %% reveal if the received header has been padded. Discard bytes + %% from the length header for this reason, to avoid creating a sub + %% binary for no useful reason. + Len = header_length(B), + Sz = min(5, size(B)), + <<B:Sz/binary, 0:(5-Sz)/unit:8, Len:24, 0:(Len-8)/unit:8>>; pack_avp(#diameter_avp{data = Data} = A) -> pack_bits(Data, A). -header_length(<<_:32, 1:1, _/bitstring>>) -> +header_length(<<_:32, 1:1, _/bits>>) -> 12; header_length(_) -> 8. |