couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nsla...@apache.org
Subject [29/30] git commit: Upgrade find_in_binary to use binary module
Date Sat, 17 Nov 2012 19:52:50 GMT
Upgrade find_in_binary to use binary module


Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/151ef2b0
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/151ef2b0
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/151ef2b0

Branch: refs/heads/docs
Commit: 151ef2b01dbe1dec68c37ac154d4d4bfabec2144
Parents: 6652937
Author: Bob Dionne <bitdiddle@apache.org>
Authored: Tue Oct 23 18:59:36 2012 -0400
Committer: Bob Dionne <bob@cloudant.com>
Committed: Tue Oct 23 18:59:36 2012 -0400

----------------------------------------------------------------------
 src/couchdb/couch_httpd.erl |   47 ++++++++++++++++++-------------------
 1 files changed, 23 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/151ef2b0/src/couchdb/couch_httpd.erl
----------------------------------------------------------------------
diff --git a/src/couchdb/couch_httpd.erl b/src/couchdb/couch_httpd.erl
index 3774b85..1fdfb0c 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


Mime
View raw message