summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Dionne <bitdiddle@apache.org>2012-10-23 18:59:36 -0400
committerBob Dionne <bob@cloudant.com>2012-10-23 18:59:36 -0400
commit151ef2b01dbe1dec68c37ac154d4d4bfabec2144 (patch)
tree57e5300a1d70bf94ae00ce7c12c957cf52a4cabf
parent66529378dd06342929e04772370f3509cbe786a5 (diff)
downloadcouchdb-151ef2b01dbe1dec68c37ac154d4d4bfabec2144.tar.gz
Upgrade find_in_binary to use binary module
-rw-r--r--src/couchdb/couch_httpd.erl47
1 files changed, 23 insertions, 24 deletions
diff --git a/src/couchdb/couch_httpd.erl b/src/couchdb/couch_httpd.erl
index 3774b85cc..1fdfb0c35 100644
--- a/src/couchdb/couch_httpd.erl
+++ b/src/couchdb/couch_httpd.erl
@@ -1045,34 +1045,33 @@ check_for_last(#mp{buffer=Buffer, data_fun=DataFun}=Mp) ->
data_fun = DataFun2})
end.
-find_in_binary(B, Data) when size(B) > 0 ->
- case size(Data) - size(B) of
- Last when Last < 0 ->
- partial_find(B, Data, 0, size(Data));
- Last ->
- find_in_binary(B, size(B), Data, 0, Last)
+find_in_binary(_B, <<>>) ->
+ not_found;
+
+find_in_binary(B, Data) ->
+ case binary:match(Data, [B], []) of
+ nomatch ->
+ partial_find(binary:part(B, {0, byte_size(B) - 1}),
+ binary:part(Data, {byte_size(Data), -byte_size(Data) + 1}), 1);
+ {Pos, _Len} ->
+ {exact, Pos}
end.
-find_in_binary(B, BS, D, N, Last) when N =< Last->
- case D of
- <<_:N/binary, B:BS/binary, _/binary>> ->
- {exact, N};
- _ ->
- find_in_binary(B, BS, D, 1 + N, Last)
+partial_find(<<>>, _Data, _Pos) ->
+ not_found;
+
+partial_find(B, Data, N) when byte_size(Data) > 0 ->
+ case binary:match(Data, [B], []) of
+ nomatch ->
+ partial_find(binary:part(B, {0, byte_size(B) - 1}),
+ binary:part(Data, {byte_size(Data), -byte_size(Data) + 1}), N + 1);
+ {Pos, _Len} ->
+ {partial, N + Pos}
end;
-find_in_binary(B, BS, D, N, Last) when N =:= 1 + Last ->
- partial_find(B, D, N, BS - 1).
-partial_find(_B, _D, _N, 0) ->
- not_found;
-partial_find(B, D, N, K) ->
- <<B1:K/binary, _/binary>> = B,
- case D of
- <<_Skip:N/binary, B1/binary>> ->
- {partial, N};
- _ ->
- partial_find(B, D, 1 + N, K - 1)
- end.
+partial_find(_B, _Data, _N) ->
+ not_found.
+
validate_bind_address(Address) ->
case inet_parse:address(Address) of