aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnders Svensson <[email protected]>2017-04-14 15:50:15 +0200
committerAnders Svensson <[email protected]>2017-06-12 16:13:52 +0200
commit3da3055f5c807c3c11a349cba6c19a5abc6bc1c7 (patch)
tree5b29b725aaa89c9100ebf03ba1282b29fb6857e9
parentdfeb8b9193ba716518cb632de8589aea378c178e (diff)
downloadotp-3da3055f5c807c3c11a349cba6c19a5abc6bc1c7.tar.gz
otp-3da3055f5c807c3c11a349cba6c19a5abc6bc1c7.tar.bz2
otp-3da3055f5c807c3c11a349cba6c19a5abc6bc1c7.zip
Remove bloat from zero encode
Don't call a function when we know the result, and consistently return a binary.
-rw-r--r--lib/diameter/include/diameter_gen.hrl4
-rw-r--r--lib/diameter/src/base/diameter_types.erl48
2 files changed, 26 insertions, 26 deletions
diff --git a/lib/diameter/include/diameter_gen.hrl b/lib/diameter/include/diameter_gen.hrl
index 9a5ca8e09f..dd8c720e68 100644
--- a/lib/diameter/include/diameter_gen.hrl
+++ b/lib/diameter/include/diameter_gen.hrl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 2010-2015. All Rights Reserved.
+%% Copyright Ericsson AB 2010-2017. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
@@ -719,7 +719,7 @@ z(Name, 1) ->
z(_, {0,_}) ->
[];
z(Name, {Min, _}) ->
- lists:duplicate(Min, z(Name)).
+ binary:copy(z(Name), Min).
z('AVP') ->
<<0:64/integer>>; %% minimal header
diff --git a/lib/diameter/src/base/diameter_types.erl b/lib/diameter/src/base/diameter_types.erl
index 6ecf385239..95361e8422 100644
--- a/lib/diameter/src/base/diameter_types.erl
+++ b/lib/diameter/src/base/diameter_types.erl
@@ -101,8 +101,8 @@
'OctetString'(decode, B) ->
?INVALID_LENGTH(B);
-'OctetString'(encode = M, zero) ->
- 'OctetString'(M, []);
+'OctetString'(encode, zero) ->
+ <<>>;
'OctetString'(encode, Str) ->
iolist_to_binary(Str).
@@ -115,8 +115,8 @@
'Integer32'(decode, B) ->
?INVALID_LENGTH(B);
-'Integer32'(encode = M, zero) ->
- 'Integer32'(M, 0);
+'Integer32'(encode, zero) ->
+ <<0:32/signed>>;
'Integer32'(encode, I)
when ?SINT(32,I) ->
@@ -130,8 +130,8 @@
'Integer64'(decode, B) ->
?INVALID_LENGTH(B);
-'Integer64'(encode = M, zero) ->
- 'Integer64'(M, 0);
+'Integer64'(encode, zero) ->
+ <<0:64/signed>>;
'Integer64'(encode, I)
when ?SINT(64,I) ->
@@ -145,8 +145,8 @@
'Unsigned32'(decode, B) ->
?INVALID_LENGTH(B);
-'Unsigned32'(encode = M, zero) ->
- 'Unsigned32'(M, 0);
+'Unsigned32'(encode, zero) ->
+ <<0:32>>;
'Unsigned32'(encode, I)
when ?UINT(32,I) ->
@@ -160,8 +160,8 @@
'Unsigned64'(decode, B) ->
?INVALID_LENGTH(B);
-'Unsigned64'(encode = M, zero) ->
- 'Unsigned64'(M, 0);
+'Unsigned64'(encode, zero) ->
+ <<0:64>>;
'Unsigned64'(encode, I)
when ?UINT(64,I) ->
@@ -193,8 +193,8 @@
'Float32'(decode, B) ->
?INVALID_LENGTH(B);
-'Float32'(encode = M, zero) ->
- 'Float32'(M, 0.0);
+'Float32'(encode, zero) ->
+ <<0.0:32/float>>;
'Float32'(encode, infinity) ->
<<0:1, 255:8, 0:23>>;
@@ -237,8 +237,8 @@
'Float64'(encode, '-infinity') ->
<<1:1, 2047:11, 0:52>>;
-'Float64'(encode = M, zero) ->
- 'Float64'(M, 0.0);
+'Float64'(encode, zero) ->
+ <<0.0:64/float>>;
'Float64'(encode, X)
when is_float(X) ->
@@ -278,8 +278,8 @@
%% A DiameterIdentity is a FQDN as definined in RFC 1035, which is at
%% least one character.
-'DiameterIdentity'(encode = M, zero) ->
- 'OctetString'(M, [0]);
+'DiameterIdentity'(encode, zero) ->
+ <<0>>;
'DiameterIdentity'(encode = M, X) ->
<<_,_/binary>> = 'OctetString'(M, X);
@@ -300,8 +300,8 @@
?INVALID_LENGTH(B);
%% The minimal DiameterURI is "aaa://x", 7 characters.
-'DiameterURI'(encode = M, zero) ->
- 'OctetString'(M, lists:duplicate(0,7));
+'DiameterURI'(encode, zero) ->
+ <<0:7/unit:8>>;
'DiameterURI'(encode, #diameter_uri{type = Type,
fqdn = DN,
@@ -332,8 +332,8 @@
%% --------------------
%% This minimal rule is "deny in 0 from 0.0.0.0 to 0.0.0.0", 33 characters.
-'IPFilterRule'(encode = M, zero) ->
- 'OctetString'(M, lists:duplicate(0,33));
+'IPFilterRule'(encode, zero) ->
+ <<0:33/unit:8>>;
'IPFilterRule'(M, X) ->
'OctetString'(M, X).
@@ -341,8 +341,8 @@
%% --------------------
%% This minimal rule is the same as for an IPFilterRule.
-'QoSFilterRule'(encode = M, zero = X) ->
- 'IPFilterRule'(M, X);
+'QoSFilterRule'(encode, zero) ->
+ <<0:33/unit:8>>;
'QoSFilterRule'(M, X) ->
'OctetString'(M, X).
@@ -362,8 +362,8 @@
'UTF8String'(decode, B) ->
?INVALID_LENGTH(B);
-'UTF8String'(encode = M, zero) ->
- 'UTF8String'(M, []);
+'UTF8String'(encode, zero) ->
+ <<>>;
'UTF8String'(encode, S) ->
<<_/binary>> = unicode:characters_to_binary(S). %% assert binary return