Skip to content

Commit e5dac9f

Browse files
committed
Speedup OpamSystem.read
1 parent c8366f7 commit e5dac9f

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

master_changes.md

+1
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,4 @@ users)
121121
## opam-format
122122

123123
## opam-core
124+
* `OpamSystem.read`: Speedup by 8% [#5896 @kit-ty-kate]

src/core/opamSystem.ml

+8-12
Original file line numberDiff line numberDiff line change
@@ -217,18 +217,14 @@ let remove_file file =
217217
)
218218

219219
let string_of_channel ic =
220-
let n = 32768 in
221-
let s = Bytes.create n in
222-
let b = Buffer.create 1024 in
223-
let rec iter ic b s =
224-
let nread =
225-
try input ic s 0 n
226-
with End_of_file -> 0 in
227-
if nread > 0 then (
228-
Buffer.add_subbytes b s 0 nread;
229-
iter ic b s
230-
) in
231-
iter ic b s;
220+
let n = 4096 in
221+
let b = Buffer.create n in
222+
let rec iter ic b =
223+
match Buffer.add_channel b ic n with
224+
| () -> iter ic b
225+
| exception End_of_file -> ()
226+
in
227+
iter ic b;
232228
Buffer.contents b
233229

234230
let read file =

0 commit comments

Comments
 (0)