diff options
author | Björn Gustavsson <[email protected]> | 2013-01-21 16:04:39 +0100 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2013-01-23 15:22:56 +0100 |
commit | 79c59e5d6199ca3410d97aac47bac3be4f5d3089 (patch) | |
tree | 24ad974b42d7b3704efa438a1db8005c952e55c8 /lib/asn1/src/asn1rtt_per_common.erl | |
parent | 392d295030b63d161b7b035faeb0e5f8797474f1 (diff) | |
download | otp-79c59e5d6199ca3410d97aac47bac3be4f5d3089.tar.gz otp-79c59e5d6199ca3410d97aac47bac3be4f5d3089.tar.bz2 otp-79c59e5d6199ca3410d97aac47bac3be4f5d3089.zip |
per,uper: Optimize decoding of the string data types
Diffstat (limited to 'lib/asn1/src/asn1rtt_per_common.erl')
-rw-r--r-- | lib/asn1/src/asn1rtt_per_common.erl | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/lib/asn1/src/asn1rtt_per_common.erl b/lib/asn1/src/asn1rtt_per_common.erl index 2edd240baf..cd6e9e2c99 100644 --- a/lib/asn1/src/asn1rtt_per_common.erl +++ b/lib/asn1/src/asn1rtt_per_common.erl @@ -24,7 +24,10 @@ -export([decode_fragmented/3, decode_compact_bit_string/1, decode_legacy_bit_string/1, - decode_named_bit_string/2]). + decode_named_bit_string/2, + decode_chars/2,decode_chars/3, + decode_chars_16bit/1, + decode_big_chars/2]). -define('16K',16384). @@ -58,6 +61,20 @@ decode_compact_bit_string(Val) -> PadLen = (8 - (bit_size(Val) band 7)) band 7, {PadLen,<<Val/bitstring,0:PadLen>>}. +decode_chars(Val, N) -> + [C || <<C:N>> <= Val]. + +decode_chars(Val, N, Chars) -> + [element(C+1, Chars) || <<C:N>> <= Val]. + +decode_chars_16bit(Val) -> + Cs = [C || <<C:16>> <= Val], + decode_chars_16bit_1(Cs). + +decode_big_chars(Val, N) -> + decode_big_chars_1(decode_chars(Val, N)). + + %%% %%% Internal functions. %%% @@ -73,3 +90,15 @@ decode_named_bit_string_1(Pos, [1|Bt], Names, Acc) -> end; decode_named_bit_string_1(_Pos, [], _Names, Acc) -> lists:reverse(Acc). + +decode_chars_16bit_1([H|T]) when H < 256 -> + [H|decode_chars_16bit_1(T)]; +decode_chars_16bit_1([H|T]) -> + [{0,0,H bsr 8,H band 255}|decode_chars_16bit_1(T)]; +decode_chars_16bit_1([]) -> []. + +decode_big_chars_1([H|T]) when H < 256 -> + [H|decode_big_chars_1(T)]; +decode_big_chars_1([H|T]) -> + [list_to_tuple(binary_to_list(<<H:32>>))|decode_big_chars_1(T)]; +decode_big_chars_1([]) -> []. |