diff options
author | Björn Gustavsson <[email protected]> | 2014-05-05 16:01:36 +0200 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2014-06-05 13:46:28 +0200 |
commit | 5faf278c471c1d01456012ce18869716c9714722 (patch) | |
tree | 05933c45999753135375a522672fbfcd77c057ec /lib/asn1/src/asn1rtt_per_common.erl | |
parent | 19058b298952fa9d5120934637a57b859012c9c2 (diff) | |
download | otp-5faf278c471c1d01456012ce18869716c9714722.tar.gz otp-5faf278c471c1d01456012ce18869716c9714722.tar.bz2 otp-5faf278c471c1d01456012ce18869716c9714722.zip |
PER: Optimize encoding of character strings with simple ranges
The encoder for the following type would generate a dialyzer warning:
Ns ::= NumericString (FROM ("0"|"1"|"2"|"3"|"4"|"5"|"6"|"7"|"8"|"9"))
Optimize this case to make it slightly faster as well as eliminate
the dialyzer warning.
Diffstat (limited to 'lib/asn1/src/asn1rtt_per_common.erl')
-rw-r--r-- | lib/asn1/src/asn1rtt_per_common.erl | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/asn1/src/asn1rtt_per_common.erl b/lib/asn1/src/asn1rtt_per_common.erl index 71fec411a0..0290c75a28 100644 --- a/lib/asn1/src/asn1rtt_per_common.erl +++ b/lib/asn1/src/asn1rtt_per_common.erl @@ -30,6 +30,7 @@ decode_big_chars/2, decode_oid/1,decode_relative_oid/1, encode_chars/2,encode_chars/3, + encode_chars_compact_map/3, encode_chars_16bit/1,encode_big_chars/1, encode_fragmented/2, encode_oid/1,encode_relative_oid/1, @@ -108,6 +109,9 @@ encode_chars(Val, NumBits) -> encode_chars(Val, NumBits, {Lb,Tab}) -> << <<(enc_char(C, Lb, Tab)):NumBits>> || C <- Val >>. +encode_chars_compact_map(Val, NumBits, {Lb,Limit}) -> + << <<(enc_char_cm(C, Lb, Limit)):NumBits>> || C <- Val >>. + encode_chars_16bit(Val) -> L = [case C of {0,0,A,B} -> [A,B]; @@ -383,6 +387,15 @@ enc_char(C0, Lb, Tab) -> illegal_char_error() end. +enc_char_cm(C0, Lb, Limit) -> + C = C0 - Lb, + if + 0 =< C, C < Limit -> + C; + true -> + illegal_char_error() + end. + illegal_char_error() -> error({error,{asn1,"value forbidden by FROM constraint"}}). |