diff options
author | Björn Gustavsson <[email protected]> | 2017-12-13 12:54:26 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2017-12-13 12:54:26 +0100 |
commit | de17c1f86974de21f0a3b1ba53c2d2b7774740de (patch) | |
tree | c32d385a51715e40d62c42af401aa42f5952ee6b /lib/kernel | |
parent | 7e0d632c9635cb2cd7f635291a9c331612400334 (diff) | |
parent | 2fb94bbae9b3ebf6bbd5b0ba3546450036764383 (diff) | |
download | otp-de17c1f86974de21f0a3b1ba53c2d2b7774740de.tar.gz otp-de17c1f86974de21f0a3b1ba53c2d2b7774740de.tar.bz2 otp-de17c1f86974de21f0a3b1ba53c2d2b7774740de.zip |
Merge pull request #1654 from bjorng/bjorn/kernel/file_io_server
Slightly optimize reading of cooked files in list mode
Diffstat (limited to 'lib/kernel')
-rw-r--r-- | lib/kernel/src/file_io_server.erl | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/lib/kernel/src/file_io_server.erl b/lib/kernel/src/file_io_server.erl index 2b35d2acfb..34d5497a4a 100644 --- a/lib/kernel/src/file_io_server.erl +++ b/lib/kernel/src/file_io_server.erl @@ -68,7 +68,8 @@ do_start(Spawn, Owner, FileName, ModeList) -> erlang:dt_restore_tag(Utag), %% process_flag(trap_exit, true), case parse_options(ModeList) of - {ReadMode, UnicodeMode, Opts} -> + {ReadMode, UnicodeMode, Opts0} -> + Opts = maybe_add_read_ahead(ReadMode, Opts0), case raw_file_io:open(FileName, [raw | Opts]) of {error, Reason} = Error -> Self ! {Ref, Error}, @@ -158,6 +159,24 @@ valid_enc({utf32,little}) -> valid_enc(_Other) -> {error,badarg}. +%% Add a small read_ahead buffer if the file is opened for reading +%% only in list mode and no read_ahead is already given. +maybe_add_read_ahead(binary, Opts) -> + Opts; +maybe_add_read_ahead(list, Opts) -> + P = fun(read_ahead) -> true; + ({read_ahead,_}) -> true; + (append) -> true; + (exclusive) -> true; + (write) -> true; + (_) -> false + end, + case lists:any(P, Opts) of + false -> + [{read_ahead, 4096}|Opts]; + true -> + Opts + end. server_loop(#state{mref = Mref} = State) -> receive |