25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-10-31 15:21:38 +01:00

Reduce size of XML stream state

This makes size of hibernated ejabberd_receiver a lot smaller (from
~290 words down to ~40).
This commit is contained in:
Janusz Dziemidowicz 2012-03-22 21:13:05 +01:00 committed by Christophe Romain
parent 674ab27700
commit e8d008c392

View File

@ -71,41 +71,44 @@
process_data(CallbackPid, Stack, Data) -> process_data(CallbackPid, Stack, Data) ->
case Data of case Data of
{?XML_START, {Name, Attrs}} -> {?XML_START, {Name, Attrs}} ->
if Stack == [] -> if
catch gen_fsm:send_event(CallbackPid, Stack == [] ->
{xmlstreamstart, Name, Attrs}); catch gen_fsm:send_event(CallbackPid,
true -> ok {xmlstreamstart, Name, Attrs}),
end, %% There is no need to store name or attributes of
[#xmlel{name = Name, attrs = Attrs, children = []} %% stream opening element as it is not used
| Stack]; %% anymore.
[xmlstreamstart];
true ->
[#xmlel{name = Name, attrs = Attrs, children = []}
| Stack]
end;
{?XML_END, EndName} -> {?XML_END, EndName} ->
case Stack of case Stack of
[xmlstreamstart] ->
catch gen_fsm:send_event(CallbackPid,
{xmlstreamend, EndName}),
[];
[#xmlel{name = Name, attrs = Attrs, children = Els} [#xmlel{name = Name, attrs = Attrs, children = Els}
| xmlstreamstart] ->
NewEl = #xmlel{name = Name, attrs = Attrs,
children = lists:reverse(Els)},
catch gen_fsm:send_event(CallbackPid,
{xmlstreamelement, NewEl}),
[xmlstreamstart];
[#xmlel{name = Name, attrs = Attrs, children = Els},
#xmlel{name = Name1, attrs = Attrs1, children = Els1}
| Tail] -> | Tail] ->
NewEl = #xmlel{name = Name, attrs = Attrs, NewEl = #xmlel{name = Name, attrs = Attrs,
children = lists:reverse(Els)}, children = lists:reverse(Els)},
case Tail of [{xmlel, Name1, Attrs1, [NewEl | Els1]} | Tail]
[] ->
catch gen_fsm:send_event(CallbackPid,
{xmlstreamend, EndName}),
Tail;
[_] ->
catch gen_fsm:send_event(CallbackPid,
{xmlstreamelement, NewEl}),
Tail;
[#xmlel{name = Name1, attrs = Attrs1, children = Els1}
| Tail1] ->
[#xmlel{name = Name1, attrs = Attrs1,
children = [NewEl | Els1]}
| Tail1]
end
end; end;
{?XML_CDATA, CData} -> {?XML_CDATA, CData} ->
case Stack of case Stack of
[El] -> [xmlstreamstart] ->
catch gen_fsm:send_all_state_event(CallbackPid, catch gen_fsm:send_all_state_event(CallbackPid,
{xmlstreamcdata, CData}), {xmlstreamcdata, CData}),
[El]; [xmlstreamstart];
%% Merge CDATA nodes if they are contiguous %% Merge CDATA nodes if they are contiguous
%% This does not change the semantic: the split in %% This does not change the semantic: the split in
%% several CDATA nodes depends on the TCP/IP packet %% several CDATA nodes depends on the TCP/IP packet