Return-Path: X-Original-To: apmail-couchdb-commits-archive@www.apache.org Delivered-To: apmail-couchdb-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id EE218DD94 for ; Tue, 23 Oct 2012 23:00:27 +0000 (UTC) Received: (qmail 39476 invoked by uid 500); 23 Oct 2012 23:00:27 -0000 Delivered-To: apmail-couchdb-commits-archive@couchdb.apache.org Received: (qmail 39389 invoked by uid 500); 23 Oct 2012 23:00:27 -0000 Mailing-List: contact commits-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list commits@couchdb.apache.org Received: (qmail 39378 invoked by uid 99); 23 Oct 2012 23:00:27 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 23 Oct 2012 23:00:27 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 13DA04E7DC; Tue, 23 Oct 2012 23:00:27 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: bitdiddle@apache.org To: commits@couchdb.apache.org X-Mailer: ASF-Git Admin Mailer Subject: git commit: Upgrade find_in_binary to use binary module Message-Id: <20121023230027.13DA04E7DC@tyr.zones.apache.org> Date: Tue, 23 Oct 2012 23:00:27 +0000 (UTC) Updated Branches: refs/heads/master 66529378d -> 151ef2b01 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/master Commit: 151ef2b01dbe1dec68c37ac154d4d4bfabec2144 Parents: 6652937 Author: Bob Dionne Authored: Tue Oct 23 18:59:36 2012 -0400 Committer: Bob Dionne 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) -> - <> = 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