Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 1 commit
  • 1 file changed
  • 0 comments
  • 1 contributor
Sep 19, 2013
Shunichi Shinohara Utilize exported function information to avoid undef thrown
Elapsed time to export XML of one node with 1000 child elements are

Before: 7msec
> Xml = [{ham, [], lists:duplicate(1000, {eggs, [], ["bacon"]})}].
> timer:tc(fun() -> lists:foreach(fun(_) -> xmerl:export_simple(Xml, xmerl_xml) end,
                                  lists:seq(1,1000)) end).
{7043822,ok}

After: 1.3 msec/call
> Xml = [{ham, [], lists:duplicate(1000, {eggs, [], ["bacon"]})}].
> timer:tc(fun() -> lists:foreach(fun(_) -> xmerl:export_simple(Xml, xmerl_xml) end,
                                  lists:seq(1,1000)) end).
{1314278,ok}
e8e7d54

Showing 1 changed file with 12 additions and 9 deletions. Show diff stats Hide diff stats

  1. 21  lib/xmerl/src/xmerl.erl
21  lib/xmerl/src/xmerl.erl
@@ -274,7 +274,7 @@ tagdef(Tag,Pos,Parents,Args,CBs) ->
274 274
 callbacks(Module) ->
275 275
     Result = check_inheritance(Module, []),
276 276
 %%%     io:format("callbacks = ~p~n", [lists:reverse(Result)]),
277  
-    lists:reverse(Result).
  277
+    gather_exports(Result, []).
278 278
 
279 279
 callbacks([M|Mods], Visited) ->
280 280
     case lists:member(M, Visited) of
@@ -296,6 +296,11 @@ check_inheritance(M, Visited) ->
296 296
 	    callbacks(Mods, [M|Visited])
297 297
     end.
298 298
 
  299
+gather_exports([M|Mods], Acc) ->
  300
+    gather_exports(Mods, [{M, M:module_info(exports)}|Acc]);
  301
+gather_exports([], Acc) ->
  302
+    Acc.
  303
+
299 304
 apply_text_cb(Ms, Text) ->
300 305
     apply_cb(Ms, '#text#', '#text#', [Text]).
301 306
 
@@ -305,14 +310,12 @@ apply_tag_cb(Ms, F, Args) ->
305 310
 apply_cb(Ms, F, Df, Args) ->
306 311
     apply_cb(Ms, F, Df, Args, Ms).
307 312
 
308  
-apply_cb([M|Ms], F, Df, Args, Ms0) ->
309  
-    case catch apply(M, F, Args) of
310  
-	{'EXIT', {undef,[{M,F,_,_}|_]}} ->
311  
-	    apply_cb(Ms, F, Df, Args, Ms0);
312  
-	{'EXIT', Reason} ->
313  
-	    exit(Reason);
314  
-	Res ->
315  
-	    Res
  313
+apply_cb([{M, Exports}|Ms], F, Df, Args, Ms0) ->
  314
+    case lists:member({F, length(Args)}, Exports) of
  315
+        true ->
  316
+            apply(M, F, Args);
  317
+        false ->
  318
+	    apply_cb(Ms, F, Df, Args, Ms0)
316 319
     end;
317 320
 apply_cb([], Df, Df, Args, _Ms0) ->
318 321
     exit({unknown_tag, {Df, Args}});

No commit comments for this range

Something went wrong with that request. Please try again.