diff options
author | Simon MacMullen <simon@rabbitmq.com> | 2014-11-13 11:10:14 +0000 |
---|---|---|
committer | Simon MacMullen <simon@rabbitmq.com> | 2014-11-13 11:10:14 +0000 |
commit | 246e224e0fd4d49de6cccb9f76f365a729da0c61 (patch) | |
tree | 059c6988e6f34ae99817bb5d261f72069b4ea601 | |
parent | b573d47f639fdc8f8b5ff869252543b00b1a8fda (diff) | |
download | rabbitmq-server-246e224e0fd4d49de6cccb9f76f365a729da0c61.tar.gz |
Small refactor suggested by Matthias.
-rw-r--r-- | src/file_handle_cache.erl | 34 |
1 files changed, 14 insertions, 20 deletions
diff --git a/src/file_handle_cache.erl b/src/file_handle_cache.erl index fa896c67..06a72aa4 100644 --- a/src/file_handle_cache.erl +++ b/src/file_handle_cache.erl @@ -845,27 +845,21 @@ maybe_seek(NewOffset, Handle = #handle{hdl = Hdl, at_eof = AtEoF}) -> {AtEoF1, NeedsSeek} = needs_seek(AtEoF, Offset, NewOffset), case NeedsSeek of + true when is_number(NewOffset) andalso + NewOffset >= Offset andalso NewOffset =< BufSz + Offset -> + Diff = NewOffset - Offset, + <<_:Diff/binary, Rest/binary>> = Buf, + {{ok, NewOffset}, Handle#handle{offset = NewOffset, + at_eof = AtEoF1, + read_buffer = Rest, + read_buffer_size = BufSz - Diff}}; true -> - case not is_number(NewOffset) orelse - NewOffset < Offset orelse - NewOffset > BufSz + Offset of - true -> - case prim_file_position(Hdl, NewOffset) of - {ok, Offset1} = Result -> - {Result, reset_read_buffer( - Handle#handle{offset = Offset1, - at_eof = AtEoF1})}; - {error, _} = Error -> - {Error, Handle} - end; - false -> - Diff = NewOffset - Offset, - <<_:Diff/binary, Rest/binary>> = Buf, - {{ok, NewOffset}, - Handle#handle{offset = NewOffset, - at_eof = AtEoF1, - read_buffer = Rest, - read_buffer_size = BufSz - Diff}} + case prim_file_position(Hdl, NewOffset) of + {ok, Offset1} = Result -> + {Result, reset_read_buffer(Handle#handle{offset = Offset1, + at_eof = AtEoF1})}; + {error, _} = Error -> + {Error, Handle} end; false -> {{ok, Offset}, Handle} |