Skip to content

Commit 33808a9

Browse files
[RTI-13897] Use integer_to_binary/1 when possible (#111)
1 parent e833df8 commit 33808a9

3 files changed

Lines changed: 14 additions & 14 deletions

File tree

src/mero.erl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -147,15 +147,15 @@ mgets(ClusterName, Keys) ->
147147
ok | {error, Reason :: term()}.
148148
add(ClusterName, Key, Value, ExpTime, Timeout)
149149
when is_atom(ClusterName), is_binary(Value), is_integer(ExpTime) ->
150-
BExpTime = list_to_binary(integer_to_list(ExpTime)),
150+
BExpTime = integer_to_binary(ExpTime),
151151
mero_conn:add(ClusterName, Key, Value, BExpTime, Timeout).
152152

153153
-spec madd(ClusterName :: atom(),
154154
[{Key :: mero_key(), Value :: binary(), ExpTime :: integer()}],
155155
Timeout :: integer()) ->
156156
[ok | {error, Reason :: term()}].
157157
madd(ClusterName, KVEs, Timeout) when is_atom(ClusterName) ->
158-
L = [{Key, Value, list_to_binary(integer_to_list(ExpTime))}
158+
L = [{Key, Value, integer_to_binary(ExpTime)}
159159
|| {Key, Value, ExpTime} <- KVEs, is_binary(Key), is_binary(Value), is_integer(ExpTime)],
160160
mero_conn:madd(ClusterName, L, Timeout).
161161

@@ -191,7 +191,7 @@ mset(ClusterName, KVEs, Timeout) ->
191191

192192
cas(ClusterName, Key, Value, ExpTime, Timeout, CAS)
193193
when is_atom(ClusterName), is_binary(Value), is_integer(ExpTime) ->
194-
BExpTime = list_to_binary(integer_to_list(ExpTime)),
194+
BExpTime = integer_to_binary(ExpTime),
195195
%% note: if CAS is undefined, this will be an unconditional set:
196196
mero_conn:set(ClusterName, Key, Value, BExpTime, Timeout, CAS).
197197

@@ -203,7 +203,7 @@ cas(ClusterName, Key, Value, ExpTime, Timeout, CAS)
203203

204204
mcas(ClusterName, KVECs, Timeout) when is_atom(ClusterName) ->
205205
%% note: if CAS is undefined, the corresponding set will be unconditional.
206-
L = [{Key, Value, list_to_binary(integer_to_list(ExpTime)), CAS}
206+
L = [{Key, Value, integer_to_binary(ExpTime), CAS}
207207
|| {Key, Value, ExpTime, CAS} <- KVECs,
208208
is_binary(Key),
209209
is_binary(Value),
@@ -234,9 +234,9 @@ increment_counter(ClusterName, Key) when is_atom(ClusterName) ->
234234
increment_counter(ClusterName, Key, Value, Initial, ExpTime, Retries, Timeout)
235235
when is_integer(Value), is_integer(ExpTime), is_atom(ClusterName), Initial >= 0,
236236
Value >= 0 ->
237-
BValue = list_to_binary(integer_to_list(Value)),
238-
BInitial = list_to_binary(integer_to_list(Initial)),
239-
BExpTime = list_to_binary(integer_to_list(ExpTime)),
237+
BValue = integer_to_binary(Value),
238+
BInitial = integer_to_binary(Initial),
239+
BExpTime = integer_to_binary(ExpTime),
240240
mero_conn:increment_counter(ClusterName,
241241
Key,
242242
BValue,
@@ -265,9 +265,9 @@ mincrement_counter(ClusterName, Keys) when is_atom(ClusterName), is_list(Keys) -
265265
mincrement_counter(ClusterName, Keys, Value, Initial, ExpTime, Timeout)
266266
when is_list(Keys), is_integer(Value), is_integer(ExpTime), is_atom(ClusterName),
267267
Initial >= 0, Value >= 0 ->
268-
BValue = list_to_binary(integer_to_list(Value)),
269-
BInitial = list_to_binary(integer_to_list(Initial)),
270-
BExpTime = list_to_binary(integer_to_list(ExpTime)),
268+
BValue = integer_to_binary(Value),
269+
BInitial = integer_to_binary(Initial),
270+
BExpTime = integer_to_binary(ExpTime),
271271
mero_conn:mincrement_counter(ClusterName, Keys, BValue, BInitial, BExpTime, Timeout).
272272

273273
-spec delete(ClusterName :: atom(), Key :: mero_key(), Timeout :: integer()) ->

src/mero_util.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ to_int(Value) when is_binary(Value) ->
2020
to_bin(Value) when is_binary(Value) ->
2121
Value;
2222
to_bin(Value) when is_integer(Value) ->
23-
to_bin(integer_to_list(Value));
23+
integer_to_binary(Value);
2424
to_bin(Value) when is_list(Value) ->
2525
list_to_binary(Value).
2626

src/mero_wrk_tcp_txt.erl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ pack({?MEMCACHE_DELETE, {Key}}) when is_binary(Key) ->
209209
pack({?MEMCACHE_DELETEQ, {Key}}) when is_binary(Key) ->
210210
[<<"delete ">>, Key, <<" noreply ">>, <<"\r\n">>];
211211
pack({?MEMCACHE_ADD, {Key, Initial, ExpTime}}) ->
212-
NBytes = integer_to_list(size(Initial)),
212+
NBytes = integer_to_binary(size(Initial)),
213213
[<<"add ">>,
214214
Key,
215215
<<" ">>,
@@ -222,7 +222,7 @@ pack({?MEMCACHE_ADD, {Key, Initial, ExpTime}}) ->
222222
Initial,
223223
<<"\r\n">>];
224224
pack({?MEMCACHE_SET, {Key, Initial, ExpTime, undefined}}) ->
225-
NBytes = integer_to_list(size(Initial)),
225+
NBytes = integer_to_binary(size(Initial)),
226226
[<<"set ">>,
227227
Key,
228228
<<" ">>,
@@ -238,7 +238,7 @@ pack({?MEMCACHE_SET, {Key, Initial, ExpTime, CAS}}) when is_integer(CAS) ->
238238
%% note: CAS should only be supplied if setting a value after looking it up. if the
239239
%% value has changed since we looked it up, the result of a cas command will be EXISTS
240240
%% (otherwise STORED).
241-
NBytes = integer_to_list(size(Initial)),
241+
NBytes = integer_to_binary(size(Initial)),
242242
[<<"cas ">>,
243243
Key,
244244
<<" ">>,

0 commit comments

Comments
 (0)