summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFilipe David Borba Manana <fdmanana@apache.org>2010-11-10 21:14:00 +0000
committerFilipe David Borba Manana <fdmanana@apache.org>2010-11-10 21:14:00 +0000
commit961d81a01f9f5f8f3c6807f143ba0678c14c4a28 (patch)
tree87e281c2db294ee89862f070bec342c417542a13 /src
parent9e53f467f89bc3942f8795f6d07f61d3f5115f88 (diff)
Micro optimization: faster header reads (read the whole block at once, so far headers are always smaller than a block). Read time is basically reduced to half.
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@1033714 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
-rw-r--r--src/couchdb/couch_file.erl15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/couchdb/couch_file.erl b/src/couchdb/couch_file.erl
index 860c9f4e..a3a728c7 100644
--- a/src/couchdb/couch_file.erl
+++ b/src/couchdb/couch_file.erl
@@ -486,11 +486,18 @@ find_header(Fd, Block) ->
end.
load_header(Fd, Block) ->
- {ok, <<1>>} = file:pread(Fd, Block*?SIZE_BLOCK, 1),
- {ok, <<HeaderLen:32/integer>>} = file:pread(Fd, (Block*?SIZE_BLOCK) + 1, 4),
+ {ok, <<1, HeaderLen:32/integer, RestBlock/binary>>} =
+ file:pread(Fd, Block * ?SIZE_BLOCK, ?SIZE_BLOCK),
TotalBytes = calculate_total_read_len(1, HeaderLen),
- {ok, <<RawBin:TotalBytes/binary>>} =
- file:pread(Fd, (Block*?SIZE_BLOCK) + 5, TotalBytes),
+ case TotalBytes > byte_size(RestBlock) of
+ false ->
+ <<RawBin:TotalBytes/binary, _/binary>> = RestBlock;
+ true ->
+ {ok, Missing} = file:pread(
+ Fd, (Block * ?SIZE_BLOCK) + 5 + byte_size(RestBlock),
+ TotalBytes - byte_size(RestBlock)),
+ RawBin = <<RestBlock/binary, Missing/binary>>
+ end,
<<Md5Sig:16/binary, HeaderBin/binary>> =
iolist_to_binary(remove_block_prefixes(1, RawBin)),
Md5Sig = couch_util:md5(HeaderBin),