summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Radestock <matthias@rabbitmq.com>2013-01-13 10:59:59 +0000
committerMatthias Radestock <matthias@rabbitmq.com>2013-01-13 10:59:59 +0000
commit63db60fd705c15fe66530fe68fedfb80c9eaaaa0 (patch)
tree3f901449f7373a19191060be6be3354c4bebd086
parent7141d5bfc377e29d6c6b8f69762b6bb865a6b414 (diff)
downloadrabbitmq-server-63db60fd705c15fe66530fe68fedfb80c9eaaaa0.tar.gz
refactor
-rw-r--r--src/rabbit_variable_queue.erl33
1 files changed, 14 insertions, 19 deletions
diff --git a/src/rabbit_variable_queue.erl b/src/rabbit_variable_queue.erl
index 185da19c..6f77b867 100644
--- a/src/rabbit_variable_queue.erl
+++ b/src/rabbit_variable_queue.erl
@@ -677,17 +677,10 @@ ackfold(MsgFun, Acc, State, AckTags) ->
{AccN, a(StateN)}.
fold(Fun, Acc, State = #vqstate{index_state = IndexState}) ->
- {Its, IndexState1} =
- lists:foldl(fun (It, {Its, IndexState2}) ->
- case next(It, IndexState2) of
- {empty, IndexState3} ->
- {Its, IndexState3};
- {value, MsgStatus, It1, IndexState3} ->
- {[{MsgStatus, It1} | Its], IndexState3}
- end
- end, {[], IndexState}, [msg_iterator(State),
- disk_ack_iterator(State),
- ram_ack_iterator(State)]),
+ {Its, IndexState1} = lists:foldl(fun inext/2, {[], IndexState},
+ [msg_iterator(State),
+ disk_ack_iterator(State),
+ ram_ack_iterator(State)]),
ifold(Fun, Acc, Its, State#vqstate{index_state = IndexState1}).
len(#vqstate { len = Len }) -> Len.
@@ -1500,6 +1493,14 @@ next({Key, Q, State}, IndexState) ->
{value, MsgStatus, Next, IndexState}
end.
+inext(It, {Its, IndexState}) ->
+ case next(It, IndexState) of
+ {empty, IndexState1} ->
+ {Its, IndexState1};
+ {value, MsgStatus1, It1, IndexState1} ->
+ {[{MsgStatus1, It1} | Its], IndexState1}
+ end.
+
ifold(_Fun, Acc, [], State) ->
{Acc, State};
ifold(Fun, Acc, Its, State) ->
@@ -1513,14 +1514,8 @@ ifold(Fun, Acc, Its, State) ->
{stop, Acc1} ->
{Acc1, State};
{cont, Acc1} ->
- case next(It, State1#vqstate.index_state) of
- {empty, IndexState1} ->
- ifold(Fun, Acc1, Rest,
- State1#vqstate{index_state = IndexState1});
- {value, MsgStatus1, It1, IndexState1} ->
- ifold(Fun, Acc1, [{MsgStatus1, It1} | Rest],
- State1#vqstate{index_state = IndexState1})
- end
+ {Its1, IndexState1} = inext(It, {Rest, State1#vqstate.index_state}),
+ ifold(Fun, Acc1, Its1, State1#vqstate{index_state = IndexState1})
end.
%%----------------------------------------------------------------------------