couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bitdid...@apache.org
Subject [1/2] git commit: Upgrade get_crlf funs to use binary BIF
Date Wed, 24 Oct 2012 10:46:23 GMT
Updated Branches:
  refs/heads/master 151ef2b01 -> 48928ae3f


Upgrade get_crlf funs to use binary BIF


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

Branch: refs/heads/master
Commit: 48928ae3fdc4dfbfe65351aa9b93cd2086ef5b15
Parents: 1d68bd4
Author: Bob Dionne <bitdiddle@apache.org>
Authored: Tue Oct 23 20:01:32 2012 -0400
Committer: Bob Dionne <bob@cloudant.com>
Committed: Tue Oct 23 20:01:32 2012 -0400

----------------------------------------------------------------------
 src/ibrowse/ibrowse_http_client.erl |   24 ++++++++++++++----------
 1 files changed, 14 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/48928ae3/src/ibrowse/ibrowse_http_client.erl
----------------------------------------------------------------------
diff --git a/src/ibrowse/ibrowse_http_client.erl b/src/ibrowse/ibrowse_http_client.erl
index fd91d40..00e8ed3 100644
--- a/src/ibrowse/ibrowse_http_client.erl
+++ b/src/ibrowse/ibrowse_http_client.erl
@@ -1458,7 +1458,7 @@ parse_header([], _) ->
     invalid.
 
 scan_header(Bin) ->
-    case get_crlf_crlf_pos(Bin, 0) of
+    case get_crlf_crlf_pos(Bin) of
         {yes, Pos} ->
             {Headers, <<_:4/binary, Body/binary>>} = split_binary(Bin, Pos),
             {yes, Headers, Body};
@@ -1474,7 +1474,7 @@ scan_header(Bin1, Bin2) ->
     Bin1_already_scanned_size = size(Bin1) - 4,
     <<Headers_prefix:Bin1_already_scanned_size/binary, Rest/binary>> = Bin1,
     Bin_to_scan = <<Rest/binary, Bin2/binary>>,
-    case get_crlf_crlf_pos(Bin_to_scan, 0) of
+    case get_crlf_crlf_pos(Bin_to_scan) of
         {yes, Pos} ->
             {Headers_suffix, <<_:4/binary, Body/binary>>} = split_binary(Bin_to_scan,
Pos),
             {yes, <<Headers_prefix/binary, Headers_suffix/binary>>, Body};
@@ -1482,9 +1482,16 @@ scan_header(Bin1, Bin2) ->
             {no, <<Bin1/binary, Bin2/binary>>}
     end.
 
-get_crlf_crlf_pos(<<$\r, $\n, $\r, $\n, _/binary>>, Pos) -> {yes, Pos};
-get_crlf_crlf_pos(<<_, Rest/binary>>, Pos)               -> get_crlf_crlf_pos(Rest,
Pos + 1);
-get_crlf_crlf_pos(<<>>, _)                               -> no.
+get_crlf_crlf_pos(Data) ->
+    binary_bif_match(Data, <<$\r, $\n, $\r, $\n>>).
+
+binary_bif_match(Data, Binary) ->
+    case binary:match(Data, Binary) of
+    {Pos, _Len} ->
+        {yes, Pos};
+    _ -> no
+    end.
+
 
 scan_crlf(Bin) ->
     case get_crlf_pos(Bin) of
@@ -1513,12 +1520,9 @@ scan_crlf_1(Bin1_head_size, Bin1, Bin2) ->
             {no, list_to_binary([Bin1, Bin2])}
     end.
 
-get_crlf_pos(Bin) ->
-    get_crlf_pos(Bin, 0).
+get_crlf_pos(Data) ->
+    binary_bif_match(Data, <<$\r, $\n>>).
 
-get_crlf_pos(<<$\r, $\n, _/binary>>, Pos) -> {yes, Pos};
-get_crlf_pos(<<_, Rest/binary>>, Pos)     -> get_crlf_pos(Rest, Pos + 1);
-get_crlf_pos(<<>>, _)                     -> no.
 
 fmt_val(L) when is_list(L)    -> L;
 fmt_val(I) when is_integer(I) -> integer_to_list(I);


Mime
View raw message