diff options
author | Matthias Radestock <matthias@rabbitmq.com> | 2011-10-01 02:42:51 +0100 |
---|---|---|
committer | Matthias Radestock <matthias@rabbitmq.com> | 2011-10-01 02:42:51 +0100 |
commit | f8482cda9fb7cc32db784c41ccffb0a3970fa9b5 (patch) | |
tree | 270ef9fd689576e4ca138990a001f2598c7b1073 | |
parent | 725544aee4c3dda7ce4f851c29c3d752d10f280f (diff) | |
download | rabbitmq-server-f8482cda9fb7cc32db784c41ccffb0a3970fa9b5.tar.gz |
refactor: one gb_trees_cons is quite enough
-rw-r--r-- | src/rabbit_amqqueue_process.erl | 9 | ||||
-rw-r--r-- | src/rabbit_mirror_queue_slave.erl | 8 | ||||
-rw-r--r-- | src/rabbit_misc.erl | 9 |
3 files changed, 11 insertions, 15 deletions
diff --git a/src/rabbit_amqqueue_process.erl b/src/rabbit_amqqueue_process.erl index e3a2ca90..d1b37a41 100644 --- a/src/rabbit_amqqueue_process.erl +++ b/src/rabbit_amqqueue_process.erl @@ -458,7 +458,8 @@ confirm_messages(MsgIds, State = #q{msg_id_to_channel = MTC}) -> fun(MsgId, {CMs, MTC0}) -> case dict:find(MsgId, MTC0) of {ok, {ChPid, MsgSeqNo}} -> - {gb_trees_cons(ChPid, MsgSeqNo, CMs), + {rabbit_misc:gb_trees_cons(ChPid, MsgSeqNo, + CMs), dict:erase(MsgId, MTC0)}; _ -> {CMs, MTC0} @@ -475,12 +476,6 @@ gb_trees_foreach(Fun, {Key, Val, It}) -> gb_trees_foreach(Fun, Tree) -> gb_trees_foreach(Fun, gb_trees:next(gb_trees:iterator(Tree))). -gb_trees_cons(Key, Value, Tree) -> - case gb_trees:lookup(Key, Tree) of - {value, Values} -> gb_trees:update(Key, [Value | Values], Tree); - none -> gb_trees:insert(Key, [Value], Tree) - end. - should_confirm_message(#delivery{msg_seq_no = undefined}, _State) -> never; should_confirm_message(#delivery{sender = ChPid, diff --git a/src/rabbit_mirror_queue_slave.erl b/src/rabbit_mirror_queue_slave.erl index 43962491..1101f220 100644 --- a/src/rabbit_mirror_queue_slave.erl +++ b/src/rabbit_mirror_queue_slave.erl @@ -407,7 +407,7 @@ confirm_messages(MsgIds, State = #state { msg_id_status = MS }) -> %% Seen from both GM and Channel. Can now %% confirm. {dict:erase(MsgId, MSN), - gb_trees_cons(ChPid, MsgSeqNo, CMsN)}; + rabbit_misc:gb_trees_cons(ChPid, MsgSeqNo, CMsN)}; {ok, {confirmed, _ChPid}} -> %% It's already been confirmed. This is %% probably it's been both sync'd to disk @@ -421,12 +421,6 @@ confirm_messages(MsgIds, State = #state { msg_id_status = MS }) -> || {ChPid, MsgSeqNos} <- gb_trees:to_list(CMs)], State #state { msg_id_status = MS1 }. -gb_trees_cons(Key, Value, Tree) -> - case gb_trees:lookup(Key, Tree) of - {value, Values} -> gb_trees:update(Key, [Value | Values], Tree); - none -> gb_trees:insert(Key, [Value], Tree) - end. - handle_process_result({ok, State}) -> noreply(State); handle_process_result({stop, State}) -> {stop, normal, State}. diff --git a/src/rabbit_misc.erl b/src/rabbit_misc.erl index f2dc97fd..e685c7d3 100644 --- a/src/rabbit_misc.erl +++ b/src/rabbit_misc.erl @@ -44,7 +44,7 @@ -export([sort_field_table/1]). -export([pid_to_string/1, string_to_pid/1]). -export([version_compare/2, version_compare/3]). --export([dict_cons/3, orddict_cons/3]). +-export([dict_cons/3, orddict_cons/3, gb_trees_cons/3]). -export([get_options/2]). -export([all_module_attributes/1, build_acyclic_graph/3]). -export([now_ms/0]). @@ -171,6 +171,7 @@ -> boolean()). -spec(dict_cons/3 :: (any(), any(), dict()) -> dict()). -spec(orddict_cons/3 :: (any(), any(), orddict:orddict()) -> orddict:orddict()). +-spec(gb_trees_cons/3 :: (any(), any(), gb_tree()) -> gb_tree()). -spec(get_options/2 :: ([optdef()], [string()]) -> {[string()], [{string(), any()}]}). -spec(all_module_attributes/1 :: (atom()) -> [{atom(), [term()]}]). @@ -669,6 +670,12 @@ dict_cons(Key, Value, Dict) -> orddict_cons(Key, Value, Dict) -> orddict:update(Key, fun (List) -> [Value | List] end, [Value], Dict). +gb_trees_cons(Key, Value, Tree) -> + case gb_trees:lookup(Key, Tree) of + {value, Values} -> gb_trees:update(Key, [Value | Values], Tree); + none -> gb_trees:insert(Key, [Value], Tree) + end. + %% Separate flags and options from arguments. %% get_options([{flag, "-q"}, {option, "-p", "/"}], %% ["set_permissions","-p","/","guest", |