aboutsummaryrefslogtreecommitdiffstats
path: root/lib/asn1/src
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2013-09-24 08:39:59 +0200
committerBjörn Gustavsson <[email protected]>2013-09-27 10:24:32 +0200
commite5210c4bc75f561383ec4f94e3dce15440f1c269 (patch)
tree58a9775259fdc19c8a80e2cb633cc2da85164029 /lib/asn1/src
parent5df3c4454fd5f302317bed7f5f83f20f7e5d9580 (diff)
downloadotp-e5210c4bc75f561383ec4f94e3dce15440f1c269.tar.gz
otp-e5210c4bc75f561383ec4f94e3dce15440f1c269.tar.bz2
otp-e5210c4bc75f561383ec4f94e3dce15440f1c269.zip
Optimize the generated decode/2 function
Use 'try' instead of 'catch', and don't match anything that cannot actually be returned from the generated encoding code.
Diffstat (limited to 'lib/asn1/src')
-rw-r--r--lib/asn1/src/asn1ct_gen.erl70
1 files changed, 26 insertions, 44 deletions
diff --git a/lib/asn1/src/asn1ct_gen.erl b/lib/asn1/src/asn1ct_gen.erl
index c526c28b70..ad2c7d9fb7 100644
--- a/lib/asn1/src/asn1ct_gen.erl
+++ b/lib/asn1/src/asn1ct_gen.erl
@@ -934,15 +934,7 @@ pgen_dispatcher(Erules,_Module,{Types,_Values,_,_,_Objects,_ObjectSets}) ->
[" Bytes ->",nl,
" {ok,",BytesAsBinary,"}",nl]
end,
- " catch",nl,
- " Class:Exception when Class =:= error; Class =:= exit ->",nl,
- " case Exception of",nl,
- " {error,Reason}=Error ->",nl,
- " Error;",nl,
- " Reason ->",nl,
- " {error,{asn1,Reason}}",nl,
- " end",nl,
- "end.",nl,nl]),
+ try_catch(),nl,nl]),
Return_rest = lists:member(undec_rest,get(encoding_options)),
Data = case {Erules,Return_rest} of
@@ -969,43 +961,22 @@ pgen_dispatcher(Erules,_Module,{Types,_Values,_,_,_Objects,_ObjectSets}) ->
_ -> "Data"
end,
- emit(["case catch decode_disp(Type,",DecWrap,") of",nl,
- " {'EXIT',{error,Reason}} ->",nl,
- " {error,Reason};",nl,
- " {'EXIT',Reason} ->",nl,
- " {error,{asn1,Reason}};",nl]),
- case {Erules,Return_rest} of
- {ber,false} ->
- emit([" Result ->",nl,
- " {ok,Result}",nl]);
- {ber,true} ->
+ emit(["try decode_disp(Type, ",DecWrap,") of",nl]),
+ case erule(Erules) of
+ ber ->
emit([" Result ->",nl,
- " {ok,Result,Rest}",nl]);
- {_,false} ->
- emit([" {X,_Rest} ->",nl,
- " {ok,X};",nl,
- " {X,_Rest,_Len} ->",nl,
- " {ok,X}",nl]);
- {per,true} ->
- emit([" {X,{_,Rest}} ->",nl,
- " {ok,X,Rest};",nl,
- " {X,{_,Rest},_Len} ->",nl,
- " {ok,X,Rest};",nl,
- " {X,Rest} ->",nl,
- " {ok,X,Rest};",nl,
- " {X,Rest,_Len} ->",nl,
- " {ok,X,Rest}",nl]);
- {uper,true} ->
- emit([" {X,{_,Rest}} ->",nl,
- " {ok,X,Rest};",nl,
- " {X,{_,Rest},_Len} ->",nl,
- " {ok,X,Rest};",nl,
- " {X,Rest} ->",nl,
- " {ok,X,Rest};",nl,
- " {X,Rest,_Len} ->",nl,
- " {ok,X,Rest}",nl])
+ case Return_rest of
+ false -> " {ok,Result}";
+ true -> " {ok,Result,Rest}"
+ end,nl]);
+ per ->
+ emit([" {Result,Rest} ->",nl,
+ case Return_rest of
+ false -> " {ok,Result}";
+ true -> " {ok,Result,Rest}"
+ end,nl])
end,
- emit(["end.",nl,nl]),
+ emit([try_catch(),nl,nl]),
gen_decode_partial_incomplete(Erules),
@@ -1021,6 +992,17 @@ pgen_dispatcher(Erules,_Module,{Types,_Values,_,_,_Objects,_ObjectSets}) ->
emit([nl]),
emit({nl,nl}).
+try_catch() ->
+ [" catch",nl,
+ " Class:Exception when Class =:= error; Class =:= exit ->",nl,
+ " case Exception of",nl,
+ " {error,Reason}=Error ->",nl,
+ " Error;",nl,
+ " Reason ->",nl,
+ " {error,{asn1,Reason}}",nl,
+ " end",nl,
+ "end."].
+
gen_info_functions(Erules) ->
emit(["encoding_rule() -> ",
{asis,Erules},".",nl,nl,