]> granicus.if.org Git - ejabberd/commitdiff
* src/xml_stream.erl: Few optimizations
authorAlexey Shchepin <alexey@process-one.net>
Thu, 26 Aug 2004 21:47:33 +0000 (21:47 +0000)
committerAlexey Shchepin <alexey@process-one.net>
Thu, 26 Aug 2004 21:47:33 +0000 (21:47 +0000)
SVN Revision: 262

ChangeLog
src/xml_stream.erl

index b12d4bed51b1dfbc00aa69a3018e8acfe7b6d16b..9e19490088fb636404cc7094bcdc58e682159f87 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -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
index 69b6123c03d357a2076110563b3dcf5af3d35093..b81575a44f03fe4cb532f76e8ae1f6638792c07a 100644 (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,
-                                              {xmlstreamelement, NewEl}),
+                                              {xmlstreamend, EndName}),
                            Tail;
-                       Len == 0 ->
+                       [_] ->
                            gen_fsm:send_event(CallbackPid,
-                                              {xmlstreamend, EndName}),
-                           Tail
+                                              {xmlstreamelement, NewEl}),
+                           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.