Skip to content

Commit

Permalink
More efficient file reading using iolists
Browse files Browse the repository at this point in the history
Change-Id: Ic242111c1c7c9e38a748fbe20e2891ab3742b574
Reviewed-on: http://review.couchbase.org/10878
Reviewed-by: Filipe David Borba Manana <fdmanana@gmail.com>
Tested-by: Chiyoung Seo <chiyoung.seo@gmail.com>
  • Loading branch information
Damien Katz authored and chiyoung committed Nov 18, 2011
1 parent 3e89972 commit 1bcd30e
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/couchdb/couch_file.erl
Expand Up @@ -408,14 +408,15 @@ load_header(Fd, Block) ->
Md5Sig = couch_util:md5(HeaderBin),
{ok, HeaderBin}.

maybe_read_more_iolist(Buffer, DataSize, _, _)
when DataSize =< byte_size(Buffer) ->
<<Data:DataSize/binary, _/binary>> = Buffer,
[Data];
maybe_read_more_iolist(Buffer, DataSize, NextPos, Fd) ->
{Missing, _} =
read_raw_iolist_int(Fd, NextPos, DataSize - byte_size(Buffer)),
[Buffer, Missing].
case iolist_size(Buffer) of
BufferSize when DataSize =< BufferSize ->
{Buffer2, _} = split_iolist(Buffer, DataSize, []),
Buffer2;
BufferSize ->
{Missing, _} = read_raw_iolist_int(Fd, NextPos, DataSize-BufferSize),
[Buffer, Missing]
end.

read_raw_iolist_int(ReadFd, {Pos, _Size}, Len) -> % 0110 UPGRADE CODE
read_raw_iolist_int(ReadFd, Pos, Len);
Expand Down Expand Up @@ -637,8 +638,8 @@ read_iolist(Fd, Pos, From) ->
_:_ ->
read_raw_iolist_int(Fd, Pos, 4)
end,
<<Prefix:1/integer, Len:31/integer, RestRawData/binary>> =
iolist_to_binary(RawData),
{Begin, RestRawData} = split_iolist(RawData, 4, []),
<<Prefix:1/integer, Len:31/integer>> = iolist_to_binary(Begin),
case Prefix of
1 ->
{Md5, IoList} = extract_md5(
Expand Down

0 comments on commit 1bcd30e

Please sign in to comment.