diff options
author | Simon MacMullen <simon@rabbitmq.com> | 2014-02-04 15:41:57 +0000 |
---|---|---|
committer | Simon MacMullen <simon@rabbitmq.com> | 2014-02-04 15:41:57 +0000 |
commit | 5c48f12df0142471becceda98a23200a4f3b5e5e (patch) | |
tree | c44048d0345b6e057d00c26fc737a6d182f36f48 /src/rabbit_queue_consumers.erl | |
parent | 986a21507654e2f23d5ee928bf2da39c4cec2e0a (diff) | |
download | rabbitmq-server-5c48f12df0142471becceda98a23200a4f3b5e5e.tar.gz |
Don't reinvent orddict:update_counter/3.
Diffstat (limited to 'src/rabbit_queue_consumers.erl')
-rw-r--r-- | src/rabbit_queue_consumers.erl | 20 |
1 files changed, 6 insertions, 14 deletions
diff --git a/src/rabbit_queue_consumers.erl b/src/rabbit_queue_consumers.erl index 46a37899..69659848 100644 --- a/src/rabbit_queue_consumers.erl +++ b/src/rabbit_queue_consumers.erl @@ -247,10 +247,11 @@ subtract_acks(ChPid, AckTags, State) -> not_found -> not_found; C = #cr{acktags = ChAckTags, limiter = Lim} -> - {CTagCounts, AckTags2} = subtract_acks(AckTags, [], [], ChAckTags), + {CTagCounts, AckTags2} = subtract_acks( + AckTags, [], orddict:new(), ChAckTags), {Unblocked, Lim2} = - lists:foldl( - fun ({CTag, Count}, {UnblockedN, LimN}) -> + orddict:fold( + fun (CTag, Count, {UnblockedN, LimN}) -> {Unblocked1, LimN1} = rabbit_limiter:ack_from_queue(LimN, CTag, Count), {UnblockedN orelse Unblocked1, LimN1} @@ -271,21 +272,12 @@ subtract_acks([T | TL] = AckTags, Prefix, CTagCounts, AckQ) -> case queue:out(AckQ) of {{value, {T, CTag}}, QTail} -> subtract_acks(TL, Prefix, - incr_ctag_count(CTag, CTagCounts), QTail); + orddict:update_counter(CTag, 1, CTagCounts), QTail); {{value, {AT, CTag}}, QTail} -> subtract_acks(AckTags, [AT | Prefix], - incr_ctag_count(CTag, CTagCounts), QTail) + orddict:update_counter(CTag, 1, CTagCounts), QTail) end. -incr_ctag_count(CTag, []) -> [{CTag, 1}]; -incr_ctag_count(CTag, [{CTag, N}]) -> [{CTag, N + 1}]; -incr_ctag_count(CTag, CTagCounts) -> case lists:keyfind(CTag, 1, CTagCounts) of - false -> [{CTag, 1} | CTagCounts]; - {CTag, N} -> [{CTag, N + 1} | - lists:keydelete( - CTag, 1, CTagCounts)] - end. - possibly_unblock(Update, ChPid, State) -> case lookup_ch(ChPid) of not_found -> unchanged; |