From aef9dbd3a6cbb85085023d3c8565740e09fd6a77 Mon Sep 17 00:00:00 2001 From: Adam Kocoloski Date: Sat, 21 Nov 2009 13:43:43 +0000 Subject: code improvements from tidier. Patch by Kostis Sagonas. COUCHDB-570 git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@882903 13f79535-47bb-0310-9956-ffa450edef68 --- src/couchdb/couch_util.erl | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) (limited to 'src/couchdb/couch_util.erl') diff --git a/src/couchdb/couch_util.erl b/src/couchdb/couch_util.erl index cdae0d4a..d02be8d9 100644 --- a/src/couchdb/couch_util.erl +++ b/src/couchdb/couch_util.erl @@ -49,11 +49,11 @@ start_driver(LibDir) -> % works like list_to_existing_atom, except can be list or binary and it % gives you the original value instead of an error if no existing atom. -to_existing_atom(V) when is_list(V)-> +to_existing_atom(V) when is_list(V) -> try list_to_existing_atom(V) catch _ -> V end; -to_existing_atom(V) when is_binary(V)-> +to_existing_atom(V) when is_binary(V) -> try list_to_existing_atom(?b2l(V)) catch _ -> V end; -to_existing_atom(V) when is_atom(V)-> +to_existing_atom(V) when is_atom(V) -> V. @@ -76,7 +76,7 @@ to_digit(N) when N < 10 -> $0 + N; to_digit(N) -> $a + N-10. -parse_term(Bin) when is_binary(Bin)-> +parse_term(Bin) when is_binary(Bin) -> parse_term(binary_to_list(Bin)); parse_term(List) -> {ok, Tokens, _} = erl_scan:string(List ++ "."), @@ -148,14 +148,14 @@ ascii_lower([], Acc) -> lists:reverse(Acc); ascii_lower([Char | RestString], Acc) when Char >= $A, Char =< $B -> ascii_lower(RestString, [Char + ($a-$A) | Acc]); -ascii_lower([Char | RestString], Acc)-> +ascii_lower([Char | RestString], Acc) -> ascii_lower(RestString, [Char | Acc]). % Is a character whitespace? -is_whitespace($\s)-> true; -is_whitespace($\t)-> true; -is_whitespace($\n)-> true; -is_whitespace($\r)-> true; +is_whitespace($\s) -> true; +is_whitespace($\t) -> true; +is_whitespace($\n) -> true; +is_whitespace($\r) -> true; is_whitespace(_Else) -> false. @@ -206,9 +206,8 @@ collate(A, B, Options) when is_binary(A), is_binary(B) -> true -> 1; % Case insensitive false -> 0 % Case sensitive end, - - SizeA = size(A), - SizeB = size(B), + SizeA = byte_size(A), + SizeB = byte_size(B), Bin = <>, [Result] = erlang:port_control(drv_port(), Operation, Bin), % Result is 0 for lt, 1 for eq and 2 for gt. Subtract 1 to return the @@ -227,9 +226,7 @@ should_flush(MemThreshHold) -> {memory, ProcMem2} = process_info(self(), memory), BinMem2 = lists:foldl(fun({_Id, Size, _NRefs}, Acc) -> Size+Acc end, 0, element(2,process_info(self(), binary))), - if ProcMem2+BinMem2 > MemThreshHold -> - true; - true -> false end; + ProcMem2+BinMem2 > MemThreshHold; true -> false end. @@ -287,7 +284,7 @@ encodeBase64Url(<<>>, Acc) -> %% %% decodeBase64(BinaryChars) -> Binary %% -decodeBase64(Cs) when is_list(Cs)-> +decodeBase64(Cs) when is_list(Cs) -> decodeBase64(list_to_binary(Cs)); decodeBase64(Cs) -> decode1(Cs, <<>>). @@ -304,7 +301,7 @@ decode1(<>, Acc) -> decode1(<<>>, Acc) -> Acc. -decodeBase64Url(Cs) when is_list(Cs)-> +decodeBase64Url(Cs) when is_list(Cs) -> decodeBase64Url(list_to_binary(Cs)); decodeBase64Url(Cs) -> decode1Url(Cs, <<>>). -- cgit v1.2.3