25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-24 16:23:40 +01:00

* src/xml_stream.erl: Few optimizations

SVN Revision: 262
This commit is contained in:
Alexey Shchepin 2004-08-26 21:47:33 +00:00
parent 6755925676
commit 1f3eb68e48
2 changed files with 27 additions and 21 deletions

View File

@ -1,3 +1,7 @@
2004-08-27 Alexey Shchepin <alexey@sevcom.net>
* src/xml_stream.erl: Few optimizations
2004-08-24 Alexey Shchepin <alexey@sevcom.net>
* src/mod_service_log.erl: Support for logging of user packets via

View File

@ -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.