nickva commented on code in PR #6015:
URL: https://github.com/apache/couchdb/pull/6015#discussion_r3319916822


##########
src/couch/src/couch_file.erl:
##########
@@ -770,19 +770,17 @@ find_newest_header(Fd, [{Location, Size} | 
LocationSizes]) ->
             find_newest_header(Fd, LocationSizes)
     end.
 
-handle_write_header(Bin, #file{fd = Fd, eof = Pos} = File) ->
+handle_write_header(Bin, #file{fd = Fd} = File) ->
     BinSize = byte_size(Bin),
+    {ok, Pos} = eof(File),
     case Pos rem ?SIZE_BLOCK of
         0 -> Padding = <<>>;
         BlockOffset -> Padding = <<0:(8 * (?SIZE_BLOCK - BlockOffset))>>
     end,
     FinalBin = [Padding, <<1, BinSize:32/integer>> | make_blocks(5, [Bin])],
-    case file:write(Fd, FinalBin) of
-        ok -> {ok, File#file{eof = Pos + iolist_size(FinalBin)}};
-        {error, Error} -> {{error, Error}, reset_eof(File)}
-    end.
+    {file:write(Fd, FinalBin), File}.
 
-read_multi_raw_iolists_int(#file{fd = Fd, eof = Eof} = File, PosLens) ->
+read_multi_raw_iolists_int(#file{fd = Fd} = File, PosLens) ->
     MapFun = fun({Pos, Len}) -> get_pread_locnum(File, Pos, Len) end,

Review Comment:
   Since getting the eof is still a syscall let's try to minimize the times we 
call it. We can get the Eof once here  and then pass it into the 
get_pread_locnum function
   
   ```erlang
   {ok, Eof} = eof(File),
   MapFun = fun({Pos, Len}) -> get_pread_locnum(File, Pos, Len, Eof) end,
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to