From 1f3eb68e488ed27829bdd2896b50e1c975670928 Mon Sep 17 00:00:00 2001 From: Alexey Shchepin Date: Thu, 26 Aug 2004 21:47:33 +0000 Subject: [PATCH] * src/xml_stream.erl: Few optimizations SVN Revision: 262 --- ChangeLog | 4 ++++ src/xml_stream.erl | 44 +++++++++++++++++++++++--------------------- 2 files changed, 27 insertions(+), 21 deletions(-) diff --git a/ChangeLog b/ChangeLog index b12d4bed5..9e1949008 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2004-08-27 Alexey Shchepin + + * src/xml_stream.erl: Few optimizations + 2004-08-24 Alexey Shchepin * src/mod_service_log.erl: Support for logging of user packets via diff --git a/src/xml_stream.erl b/src/xml_stream.erl index 69b6123c0..b81575a44 100644 --- a/src/xml_stream.erl +++ b/src/xml_stream.erl @@ -47,41 +47,43 @@ loop(CallbackPid, Port, Stack) -> process_data(CallbackPid, Stack, Data) -> case Data of {?XML_START, {Name, Attrs}} -> - if Stack == [] -> + if + Stack == [] -> gen_fsm:send_event(CallbackPid, {xmlstreamstart, Name, Attrs}); - true -> true + true -> + ok end, [{xmlelement, Name, Attrs, []} | Stack]; {?XML_END, EndName} -> case Stack of [{xmlelement, Name, Attrs, Els} | Tail] -> NewEl = {xmlelement, Name, Attrs, lists:reverse(Els)}, - Len = length(Tail), - if - Len > 1 -> add_subelement(NewEl, Tail); - Len == 1 -> + case Tail of + [] -> + gen_fsm:send_event(CallbackPid, + {xmlstreamend, EndName}), + Tail; + [_] -> gen_fsm:send_event(CallbackPid, {xmlstreamelement, NewEl}), Tail; - Len == 0 -> - gen_fsm:send_event(CallbackPid, - {xmlstreamend, EndName}), - Tail + [{xmlelement, Name1, Attrs1, Els1} | Tail1] -> + [{xmlelement, Name1, Attrs1, [NewEl | Els1]} | + Tail1] end end; {?XML_CDATA, CData} -> - add_subelement({xmlcdata, CData}, Stack); - {?XML_ERROR, Err} -> gen_fsm:send_event(CallbackPid, - {xmlstreamerror, Err}) - end. - - -add_subelement(El, Stack) -> - case Stack of - [{xmlelement, Name, Attrs, Els} | Tail] -> - [{xmlelement, Name, Attrs, [El | Els]} | Tail]; - [] -> [] + case Stack of + [El] -> + [El]; + [{xmlelement, Name, Attrs, Els} | Tail] -> + [{xmlelement, Name, Attrs, [{xmlcdata, CData} | Els]} | + Tail]; + [] -> [] + end; + {?XML_ERROR, Err} -> + gen_fsm:send_event(CallbackPid, {xmlstreamerror, Err}) end.