From 83aa3f1b9c7aeafaed2b798f75bea929e5090ed0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Wed, 10 Aug 2016 17:50:28 +0200 Subject: Use binary_to_integer instead of to list and back --- src/cowboy_constraints.erl | 2 +- src/cowboy_http.erl | 2 +- src/cowboy_websocket.erl | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/cowboy_constraints.erl b/src/cowboy_constraints.erl index 9a379e1..9bd578e 100644 --- a/src/cowboy_constraints.erl +++ b/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. diff --git a/src/cowboy_http.erl b/src/cowboy_http.erl index 773f891..5ec7d0e 100644 --- a/src/cowboy_http.erl +++ b/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) -> diff --git a/src/cowboy_websocket.erl b/src/cowboy_websocket.erl index 603889f..693a920 100644 --- a/src/cowboy_websocket.erl +++ b/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), -- cgit v1.2.3