Skip to content

Commit 73dab0c

Browse files
ansdkjnilsson
authored andcommitted
Generate less garbage
1 parent dfacd33 commit 73dab0c

File tree

3 files changed

+48
-53
lines changed

3 files changed

+48
-53
lines changed

deps/rabbit/src/rabbit_fifo.erl

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -731,13 +731,11 @@ update_waiting_consumer_status(Node,
731731
#?STATE{waiting_consumers = WaitingConsumers},
732732
Status) ->
733733
sort_waiting(
734-
[begin
735-
case node(Pid) of
736-
Node ->
737-
{ConsumerKey, Consumer#consumer{status = Status}};
738-
_ ->
739-
{ConsumerKey, Consumer}
740-
end
734+
[case node(Pid) of
735+
Node ->
736+
{ConsumerKey, Consumer#consumer{status = Status}};
737+
_ ->
738+
{ConsumerKey, Consumer}
741739
end || {ConsumerKey, ?CONSUMER_PID(Pid) = Consumer}
742740
<- WaitingConsumers, Consumer#consumer.status =/= cancelled]).
743741

@@ -1931,9 +1929,9 @@ take_next_msg(#?STATE{returns = Returns0,
19311929
{NextMsg, State#?STATE{returns = Returns}};
19321930
{empty, _} ->
19331931
case rabbit_fifo_q:out(Messages0) of
1934-
{empty, _} ->
1932+
empty ->
19351933
empty;
1936-
{_P, ?MSG(RaftIdx, _) = Msg, Messages} ->
1934+
{?MSG(RaftIdx, _) = Msg, Messages} ->
19371935
%% add index here
19381936
Indexes = rabbit_fifo_index:append(RaftIdx, Indexes0),
19391937
{Msg, State#?STATE{messages = Messages,
@@ -2236,7 +2234,6 @@ sort_waiting(Waiting) ->
22362234
Status /= up
22372235
end, Waiting).
22382236

2239-
22402237
merge_consumer(_Meta, #consumer{cfg = CCfg, checked_out = Checked} = Consumer,
22412238
ConsumerMeta, {Life, Mode}, Priority) ->
22422239
Credit = included_credit(Mode),

deps/rabbit/src/rabbit_fifo_q.erl

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,9 @@ in(lo, Item, #?MODULE{lo = Lo, len = Len} = State) ->
3939
len = Len + 1}.
4040

4141
-spec out(state()) ->
42-
{empty, state()} |
43-
{hi | lo, msg(), state()}.
44-
out(#?MODULE{len = 0} = S) ->
45-
{empty, S};
42+
empty | {msg(), state()}.
43+
out(#?MODULE{len = 0}) ->
44+
empty;
4645
out(#?MODULE{hi = Hi0,
4746
lo = Lo0,
4847
len = Len,
@@ -55,13 +54,13 @@ out(#?MODULE{hi = Hi0,
5554
end,
5655
case next(State) of
5756
{hi, Msg} ->
58-
{hi, Msg, State#?MODULE{hi = drop(Hi0),
59-
dequeue_counter = C,
60-
len = Len - 1}};
57+
{Msg, State#?MODULE{hi = drop(Hi0),
58+
dequeue_counter = C,
59+
len = Len - 1}};
6160
{lo, Msg} ->
62-
{lo, Msg, State#?MODULE{lo = drop(Lo0),
63-
dequeue_counter = C,
64-
len = Len - 1}}
61+
{Msg, State#?MODULE{lo = drop(Lo0),
62+
dequeue_counter = C,
63+
len = Len - 1}}
6564
end.
6665

6766
-spec get(state()) -> empty | msg().

deps/rabbit/test/rabbit_fifo_q_SUITE.erl

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ hi(_Config) ->
5959
fun ({P, I}, Q) ->
6060
rabbit_fifo_q:in(P, I, Q)
6161
end, Q0, [
62-
{hi, ?MSG(?LINE)}
62+
{hi, ?MSG(1)}
6363
]),
64-
{hi, _, Q2} = rabbit_fifo_q:out(Q1),
65-
{empty, _Q3} = rabbit_fifo_q:out(Q2),
64+
{?MSG(1), Q2} = rabbit_fifo_q:out(Q1),
65+
empty = rabbit_fifo_q:out(Q2),
6666
ok.
6767

6868
basics(_Config) ->
@@ -71,18 +71,18 @@ basics(_Config) ->
7171
fun ({P, I}, Q) ->
7272
rabbit_fifo_q:in(P, I, Q)
7373
end, Q0, [
74-
{hi, ?MSG(?LINE)},
75-
{lo, ?MSG(?LINE)},
76-
{hi, ?MSG(?LINE)},
77-
{lo, ?MSG(?LINE)},
78-
{hi, ?MSG(?LINE)}
74+
{hi, ?MSG(1)},
75+
{lo, ?MSG(2)},
76+
{hi, ?MSG(3)},
77+
{lo, ?MSG(4)},
78+
{hi, ?MSG(5)}
7979
]),
80-
{hi, _, Q2} = rabbit_fifo_q:out(Q1),
81-
{hi, _, Q3} = rabbit_fifo_q:out(Q2),
82-
{lo, _, Q4} = rabbit_fifo_q:out(Q3),
83-
{hi, _, Q5} = rabbit_fifo_q:out(Q4),
84-
{lo, _, Q6} = rabbit_fifo_q:out(Q5),
85-
{empty, _} = rabbit_fifo_q:out(Q6),
80+
{?MSG(1), Q2} = rabbit_fifo_q:out(Q1),
81+
{?MSG(3), Q3} = rabbit_fifo_q:out(Q2),
82+
{?MSG(2), Q4} = rabbit_fifo_q:out(Q3),
83+
{?MSG(5), Q5} = rabbit_fifo_q:out(Q4),
84+
{?MSG(4), Q6} = rabbit_fifo_q:out(Q5),
85+
empty = rabbit_fifo_q:out(Q6),
8686
ok.
8787

8888
hi_is_prioritised(_Config) ->
@@ -93,29 +93,28 @@ hi_is_prioritised(_Config) ->
9393
fun ({P, I}, Q) ->
9494
rabbit_fifo_q:in(P, I, Q)
9595
end, Q0, [
96-
{hi, ?MSG(1, ?LINE)},
97-
{hi, ?MSG(2, ?LINE)},
98-
{hi, ?MSG(3, ?LINE)},
99-
{hi, ?MSG(4, ?LINE)},
100-
{lo, ?MSG(5, ?LINE)}
96+
{hi, ?MSG(1)},
97+
{hi, ?MSG(2)},
98+
{hi, ?MSG(3)},
99+
{hi, ?MSG(4)},
100+
{lo, ?MSG(5)}
101101
]),
102-
{hi, _, Q2} = rabbit_fifo_q:out(Q1),
103-
{hi, _, Q3} = rabbit_fifo_q:out(Q2),
104-
{hi, _, Q4} = rabbit_fifo_q:out(Q3),
105-
{hi, _, Q5} = rabbit_fifo_q:out(Q4),
106-
{lo, _, Q6} = rabbit_fifo_q:out(Q5),
107-
{empty, _} = rabbit_fifo_q:out(Q6),
108-
102+
{?MSG(1), Q2} = rabbit_fifo_q:out(Q1),
103+
{?MSG(2), Q3} = rabbit_fifo_q:out(Q2),
104+
{?MSG(3), Q4} = rabbit_fifo_q:out(Q3),
105+
{?MSG(4), Q5} = rabbit_fifo_q:out(Q4),
106+
{?MSG(5), Q6} = rabbit_fifo_q:out(Q5),
107+
empty = rabbit_fifo_q:out(Q6),
109108
ok.
110109

111110
get_lowest_index(_Config) ->
112111
Q0 = rabbit_fifo_q:new(),
113112
Q1 = rabbit_fifo_q:in(hi, ?MSG(1, ?LINE), Q0),
114113
Q2 = rabbit_fifo_q:in(lo, ?MSG(2, ?LINE), Q1),
115114
Q3 = rabbit_fifo_q:in(lo, ?MSG(3, ?LINE), Q2),
116-
{hi, _, Q4} = rabbit_fifo_q:out(Q3),
117-
{lo, _, Q5} = rabbit_fifo_q:out(Q4),
118-
{lo, _, Q6} = rabbit_fifo_q:out(Q5),
115+
{_, Q4} = rabbit_fifo_q:out(Q3),
116+
{_, Q5} = rabbit_fifo_q:out(Q4),
117+
{_, Q6} = rabbit_fifo_q:out(Q5),
119118

120119
?assertEqual(undefined, rabbit_fifo_q:get_lowest_index(Q0)),
121120
?assertEqual(1, rabbit_fifo_q:get_lowest_index(Q1)),
@@ -151,14 +150,14 @@ queue_prop(P, Ops) ->
151150
end;
152151
(out, {Q0, S0}) ->
153152
{V1, Q} = case queue:out(Q0) of
154-
{{value, V_}, Q1} ->
155-
{V_, Q1};
153+
{{value, V0}, Q1} ->
154+
{V0, Q1};
156155
Res0 ->
157156
Res0
158157
end,
159158
{V2, S} = case rabbit_fifo_q:out(S0) of
160-
{_, V, S1} ->
161-
{V, S1};
159+
empty ->
160+
{empty, S0};
162161
Res ->
163162
Res
164163
end,

0 commit comments

Comments
 (0)