From 49a4c58106ca913328b5f28e7124e820b15e4b43 Mon Sep 17 00:00:00 2001 From: Gustav Simonsson Date: Tue, 3 Jul 2012 17:17:00 +0200 Subject: Keep encoded octets of constrained whole number value and range as binaries and use erlang:byte_size to get length of octets and range. For speed. --- lib/asn1/src/asn1rt_per_bin.erl | 8 ++++---- lib/asn1/src/asn1rt_per_bin_rt2ct.erl | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'lib/asn1/src') diff --git a/lib/asn1/src/asn1rt_per_bin.erl b/lib/asn1/src/asn1rt_per_bin.erl index 4e0c12936c..85988aa21d 100644 --- a/lib/asn1/src/asn1rt_per_bin.erl +++ b/lib/asn1/src/asn1rt_per_bin.erl @@ -695,10 +695,10 @@ encode_constrained_number({Lb,Ub},Val) when Val >= Lb, Ub >= Val -> Range =< 65536 -> {octets,<>}; Range =< (1 bsl (255*8)) -> - Octs = binary:bin_to_list(binary:encode_unsigned(Val2)), - RangeOcts = binary:bin_to_list(binary:encode_unsigned(Range - 1)), - OctsLen = length(Octs), - RangeOctsLen = length(RangeOcts), + Octs = binary:encode_unsigned(Val2), + RangeOcts = binary:encode_unsigned(Range - 1), + OctsLen = erlang:byte_size(Octs), + RangeOctsLen = erlang:byte_size(RangeOcts), LengthBitsNeeded = minimum_bits(RangeOctsLen - 1), [{bits, LengthBitsNeeded, OctsLen - 1}, {octets, Octs}]; true -> diff --git a/lib/asn1/src/asn1rt_per_bin_rt2ct.erl b/lib/asn1/src/asn1rt_per_bin_rt2ct.erl index f2e93cf096..46d4bcb065 100644 --- a/lib/asn1/src/asn1rt_per_bin_rt2ct.erl +++ b/lib/asn1/src/asn1rt_per_bin_rt2ct.erl @@ -605,10 +605,10 @@ encode_constrained_number({Lb,Ub},Val) when Val >= Lb, Ub >= Val -> % Size = {octets,<>}; [20,2,<>]; Range =< (1 bsl (255*8)) -> - Octs = binary:bin_to_list(binary:encode_unsigned(Val2)), - RangeOcts = binary:bin_to_list(binary:encode_unsigned(Range - 1)), - OctsLen = length(Octs), - RangeOctsLen = length(RangeOcts), + Octs = binary:encode_unsigned(Val2), + RangeOcts = binary:encode_unsigned(Range - 1), + OctsLen = erlang:byte_size(Octs), + RangeOctsLen = erlang:byte_size(RangeOcts), LengthBitsNeeded = asn1rt_per_bin:minimum_bits(RangeOctsLen - 1), [10,LengthBitsNeeded,OctsLen-1,20,OctsLen,Octs]; true -> -- cgit v1.2.3