aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2013-07-02 07:08:31 +0200
committerBjörn Gustavsson <[email protected]>2013-08-30 10:13:17 +0200
commit4c10999bf32603e81b597cbc3e43e7dbe4d94a04 (patch)
tree73bf25a94ffa109e85cd08c54ac79d4420326b09
parentc0fce14273c4933cc1af8006c3975cfabd2ad0ad (diff)
downloadotp-4c10999bf32603e81b597cbc3e43e7dbe4d94a04.tar.gz
otp-4c10999bf32603e81b597cbc3e43e7dbe4d94a04.tar.bz2
otp-4c10999bf32603e81b597cbc3e43e7dbe4d94a04.zip
Optimize the generated encode/2 function
Use 'try' instead of 'catch', and don't match anything that cannot actually be returned from the generated encoding code.
-rw-r--r--lib/asn1/src/asn1ct_gen.erl26
1 files changed, 17 insertions, 9 deletions
diff --git a/lib/asn1/src/asn1ct_gen.erl b/lib/asn1/src/asn1ct_gen.erl
index acbd1026ff..68da80c585 100644
--- a/lib/asn1/src/asn1ct_gen.erl
+++ b/lib/asn1/src/asn1ct_gen.erl
@@ -916,15 +916,23 @@ pgen_dispatcher(Erules,_Module,{Types,_Values,_,_,_Objects,_ObjectSets}) ->
{["complete(encode_disp(Type, Data))"],"Bytes"}
end,
emit(["encode(Type,Data) ->",nl,
- "case catch ",Call," of",nl,
- " {'EXIT',{error,Reason}} ->",nl,
- " {error,Reason};",nl,
- " {'EXIT',Reason} ->",nl,
- " {error,{asn1,Reason}};",nl,
- " {Bytes,_Len} ->",nl,
- " {ok,",BytesAsBinary,"};",nl,
- " Bytes ->",nl,
- " {ok,",BytesAsBinary,"}",nl,
+ "try ",Call," of",nl,
+ case erule(Erules) of
+ ber ->
+ [" {Bytes,_Len} ->",nl,
+ " {ok,",BytesAsBinary,"}",nl];
+ per ->
+ [" 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]),
Return_rest = lists:member(undec_rest,get(encoding_options)),