diff options
| author | Matthew Sackman <matthew@rabbitmq.com> | 2011-07-28 15:02:11 +0100 |
|---|---|---|
| committer | Matthew Sackman <matthew@rabbitmq.com> | 2011-07-28 15:02:11 +0100 |
| commit | 031179d8deea02070cecfe54dd251f73c00a9844 (patch) | |
| tree | d832c14805b48e417571530e2aee2c4b3793c886 /src | |
| parent | 9d08c2abc95443ce9a4ffef1098a7ec48d879a20 (diff) | |
| download | rabbitmq-server-git-031179d8deea02070cecfe54dd251f73c00a9844.tar.gz | |
Minor refactor and introduce horrific inefficiency
Diffstat (limited to 'src')
| -rw-r--r-- | src/priority_queue.erl | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/src/priority_queue.erl b/src/priority_queue.erl index ccc87cd5ac..3478790391 100644 --- a/src/priority_queue.erl +++ b/src/priority_queue.erl @@ -90,12 +90,8 @@ len({pqueue, Queues}) -> to_list({queue, In, Out}) when is_list(In), is_list(Out) -> [{0, V} || V <- Out ++ lists:reverse(In, [])]; to_list({pqueue, Queues}) -> - [{P1, V} || {P, Q} <- Queues, - case P of - infinity -> P1 = P, true; - _ -> P1 = -P, true - end, - {0, V} <- to_list(Q)]. + [{maybe_negate_priority(P), V} || {P, Q} <- Queues, + {0, V} <- to_list(Q)]. in(Item, Q) -> in(Item, 0, Q). @@ -109,10 +105,7 @@ in(X, Priority, _Q = {queue, [], []}) -> in(X, Priority, Q = {queue, _, _}) -> in(X, Priority, {pqueue, [{0, Q}]}); in(X, Priority, {pqueue, Queues}) -> - P = case Priority of - infinity -> Priority; - _ -> -Priority - end, + P = maybe_negate_priority(Priority), {pqueue, case lists:keysearch(P, 1, Queues) of {value, {_, Q}} -> lists:keyreplace(P, 1, Queues, {P, in(X, Q)}); @@ -193,3 +186,6 @@ r2f([]) -> {queue, [], []}; r2f([_] = R) -> {queue, [], R}; r2f([X,Y]) -> {queue, [X], [Y]}; r2f([X,Y|R]) -> {queue, [X,Y], lists:reverse(R, [])}. + +maybe_negate_priority(infinity) -> infinity; +maybe_negate_priority(P) -> -P. |
