Skip to content
Browse files

patch from Kostis Sagonas, obtained by using tidier, a tool that tidi…

…es Erlang code
  • Loading branch information...
1 parent bce9e3d commit 6d300dbd619f76b109c4c259d6860b03fd7c71cf @etrepum etrepum committed
Showing with 26 additions and 53 deletions.
  1. +1 −6 src/mochijson.erl
  2. +1 −6 src/mochijson2.erl
  3. +21 −33 src/mochiweb_multipart.erl
  4. +1 −3 src/mochiweb_request.erl
  5. +1 −3 src/mochiweb_util.erl
  6. +1 −2 src/reloader.erl
View
7 src/mochijson.erl
@@ -460,12 +460,7 @@ equiv_object(Props1, Props2) ->
equiv_list([], []) ->
true;
equiv_list([V1 | L1], [V2 | L2]) ->
- case equiv(V1, V2) of
- true ->
- equiv_list(L1, L2);
- false ->
- false
- end.
+ equiv(V1, V2) andalso equiv_list(L1, L2).
test_all() ->
test_issue33(),
View
7 src/mochijson2.erl
@@ -550,12 +550,7 @@ equiv_object(Props1, Props2) ->
equiv_list([], []) ->
true;
equiv_list([V1 | L1], [V2 | L2]) ->
- case equiv(V1, V2) of
- true ->
- equiv_list(L1, L2);
- false ->
- false
- end.
+ equiv(V1, V2) andalso equiv_list(L1, L2).
test_all() ->
[1199344435545.0, 1] = decode(<<"[1199344435545.0,1]">>),
View
54 src/mochiweb_multipart.erl
@@ -76,9 +76,9 @@ parse_multipart_request(Req, Callback) ->
Boundary = iolist_to_binary(
get_boundary(Req:get_header_value("content-type"))),
Prefix = <<"\r\n--", Boundary/binary>>,
- BS = size(Boundary),
+ BS = byte_size(Boundary),
Chunk = read_chunk(Req, Length),
- Length1 = Length - size(Chunk),
+ Length1 = Length - byte_size(Chunk),
<<"--", Boundary:BS/binary, "\r\n", Rest/binary>> = Chunk,
feed_mp(headers, flash_multipart_hack(#mp{boundary=Prefix,
length=Length1,
@@ -117,7 +117,7 @@ read_chunk(Req, Length) when Length > 0 ->
read_more(State=#mp{length=Length, buffer=Buffer, req=Req}) ->
Data = read_chunk(Req, Length),
Buffer1 = <<Buffer/binary, Data/binary>>,
- flash_multipart_hack(State#mp{length=Length - size(Data),
+ flash_multipart_hack(State#mp{length=Length - byte_size(Data),
buffer=Buffer1}).
flash_multipart_hack(State=#mp{length=0, buffer=Buffer, boundary=Prefix}) ->
@@ -285,14 +285,12 @@ test_parse3() ->
eof],
TestCallback = fun (Next) -> test_callback(Next, Expect) end,
ServerFun = fun (Socket) ->
- case gen_tcp:send(Socket, BinContent) of
- ok ->
- exit(normal)
- end
+ ok = gen_tcp:send(Socket, BinContent),
+ exit(normal)
end,
ClientFun = fun (Socket) ->
Req = fake_request(Socket, ContentType,
- size(BinContent)),
+ byte_size(BinContent)),
Res = parse_multipart_request(Req, TestCallback),
{0, <<>>, ok} = Res,
ok
@@ -318,14 +316,12 @@ test_parse2() ->
eof],
TestCallback = fun (Next) -> test_callback(Next, Expect) end,
ServerFun = fun (Socket) ->
- case gen_tcp:send(Socket, BinContent) of
- ok ->
- exit(normal)
- end
+ ok = gen_tcp:send(Socket, BinContent),
+ exit(normal)
end,
ClientFun = fun (Socket) ->
Req = fake_request(Socket, ContentType,
- size(BinContent)),
+ byte_size(BinContent)),
Res = parse_multipart_request(Req, TestCallback),
{0, <<>>, ok} = Res,
ok
@@ -351,14 +347,12 @@ test_parse_form() ->
""], "\r\n"),
BinContent = iolist_to_binary(Content),
ServerFun = fun (Socket) ->
- case gen_tcp:send(Socket, BinContent) of
- ok ->
- exit(normal)
- end
+ ok = gen_tcp:send(Socket, BinContent),
+ exit(normal)
end,
ClientFun = fun (Socket) ->
Req = fake_request(Socket, ContentType,
- size(BinContent)),
+ byte_size(BinContent)),
Res = parse_form(Req),
[{"submit-name", "Larry"},
{"files", {"file1.txt", {"text/plain",[]},
@@ -400,14 +394,12 @@ test_parse() ->
eof],
TestCallback = fun (Next) -> test_callback(Next, Expect) end,
ServerFun = fun (Socket) ->
- case gen_tcp:send(Socket, BinContent) of
- ok ->
- exit(normal)
- end
+ ok = gen_tcp:send(Socket, BinContent),
+ exit(normal)
end,
ClientFun = fun (Socket) ->
Req = fake_request(Socket, ContentType,
- size(BinContent)),
+ byte_size(BinContent)),
Res = parse_multipart_request(Req, TestCallback),
{0, <<>>, ok} = Res,
ok
@@ -471,14 +463,12 @@ test_flash_parse() ->
eof],
TestCallback = fun (Next) -> test_callback(Next, Expect) end,
ServerFun = fun (Socket) ->
- case gen_tcp:send(Socket, BinContent) of
- ok ->
- exit(normal)
- end
+ ok = gen_tcp:send(Socket, BinContent),
+ exit(normal)
end,
ClientFun = fun (Socket) ->
Req = fake_request(Socket, ContentType,
- size(BinContent)),
+ byte_size(BinContent)),
Res = parse_multipart_request(Req, TestCallback),
{0, <<>>, ok} = Res,
ok
@@ -515,14 +505,12 @@ test_flash_parse2() ->
eof],
TestCallback = fun (Next) -> test_callback(Next, Expect) end,
ServerFun = fun (Socket) ->
- case gen_tcp:send(Socket, BinContent) of
- ok ->
- exit(normal)
- end
+ ok = gen_tcp:send(Socket, BinContent),
+ exit(normal)
end,
ClientFun = fun (Socket) ->
Req = fake_request(Socket, ContentType,
- size(BinContent)),
+ byte_size(BinContent)),
Res = parse_multipart_request(Req, TestCallback),
{0, <<>>, ok} = Res,
ok
View
4 src/mochiweb_request.erl
@@ -676,7 +676,6 @@ range_parts({file, IoDevice}, Ranges) ->
end,
LocNums, Data),
{Bodies, Size};
-
range_parts(Body0, Ranges) ->
Body = iolist_to_binary(Body0),
Size = size(Body),
@@ -743,7 +742,6 @@ test_range() ->
[{none, 20}] = parse_range_request("bytes=-20"),
io:format(".. ok ~n"),
-
%% invalid, single ranges
io:format("Testing parse_range_request with invalid ranges~n"),
io:format("1"),
@@ -771,7 +769,7 @@ test_range() ->
io:format(".. ok~n"),
Body = <<"012345678901234567890123456789012345678901234567890123456789">>,
- BodySize = size(Body), %% 60
+ BodySize = byte_size(Body), %% 60
BodySize = 60,
%% these values assume BodySize =:= 60
View
4 src/mochiweb_util.erl
@@ -423,9 +423,7 @@ record_to_proplist(Record, Fields) ->
%% Fields should be obtained by calling record_info(fields, record_type)
%% where record_type is the record type of Record
record_to_proplist(Record, Fields, TypeKey)
- when is_tuple(Record),
- is_list(Fields),
- size(Record) - 1 =:= length(Fields) ->
+ when tuple_size(Record) - 1 =:= length(Fields) ->
lists:zip([TypeKey | Fields], tuple_to_list(Record)).
View
3 src/reloader.erl
@@ -78,8 +78,7 @@ code_change(_Vsn, State, _Extra) ->
doit(From, To) ->
[case file:read_file_info(Filename) of
- {ok, FileInfo} when FileInfo#file_info.mtime >= From,
- FileInfo#file_info.mtime < To ->
+ {ok, #file_info{mtime = Mtime}} when Mtime >= From, Mtime < To ->
reload(Module);
{ok, _} ->
unmodified;

0 comments on commit 6d300db

Please sign in to comment.
Something went wrong with that request. Please try again.