Browse Source

Use binary_to_integer instead of to list and back

Loïc Hoguin 8 years ago
parent
commit
83aa3f1b9c

+ 1 - 1
src/cowboy_constraints.erl

@@ -52,7 +52,7 @@ apply_constraint(Value, F) when is_function(F) ->
 %% Constraint functions.
 
 int(Value) when is_binary(Value) ->
-	try {true, list_to_integer(binary_to_list(Value))}
+	try {true, binary_to_integer(Value)}
 	catch _:_ -> false
 	end.
 

+ 1 - 1
src/cowboy_http.erl

@@ -578,7 +578,7 @@ parse_host(<< $[, Rest/bits >>, false, <<>>) ->
 parse_host(<<>>, false, Acc) ->
 	{Acc, undefined};
 parse_host(<< $:, Rest/bits >>, false, Acc) ->
-	{Acc, list_to_integer(binary_to_list(Rest))};
+	{Acc, binary_to_integer(Rest)};
 parse_host(<< $], Rest/bits >>, true, Acc) ->
 	parse_host(Rest, false, << Acc/binary, $] >>);
 parse_host(<< C, Rest/bits >>, E, Acc) ->

+ 1 - 1
src/cowboy_websocket.erl

@@ -91,7 +91,7 @@ websocket_upgrade(State, Req) ->
 	%% @todo Should probably send a 426 if the Upgrade header is missing.
 	[<<"websocket">>] = cowboy_req:parse_header(<<"upgrade">>, Req),
 	Version = cowboy_req:header(<<"sec-websocket-version">>, Req),
-	IntVersion = list_to_integer(binary_to_list(Version)),
+	IntVersion = binary_to_integer(Version),
 	true = (IntVersion =:= 7) orelse (IntVersion =:= 8)
 		orelse (IntVersion =:= 13),
 	Key = cowboy_req:header(<<"sec-websocket-key">>, Req),

+ 1 - 1
test/http_SUITE_data/http_multipart_stream.erl

@@ -11,7 +11,7 @@ init(Req, Opts) ->
 multipart(Req) ->
 	case cowboy_req:read_part(Req) of
 		{ok, [{<<"content-length">>, BinLength}], Req2} ->
-			Length = list_to_integer(binary_to_list(BinLength)),
+			Length = binary_to_integer(BinLength),
 			{Length, Req3} = stream_body(Req2, 0),
 			multipart(Req3);
 		{done, Req2} ->