Skip to content

Commit 69841b7

Browse files
committed
Speedup OpamSystem.read
1 parent cb2181b commit 69841b7

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
@@ -164,3 +164,4 @@ users)
164164
* Add `OpamTypesBase.switch_selections_{compare,equal}`: proper comparison functions for `OpamTypes.switch_selections` [#6102 @kit-ty-kate]
165165

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

src/core/opamSystem.ml

+8-12
Original file line numberDiff line numberDiff line change
@@ -222,18 +222,14 @@ let remove_file file =
222222
)
223223

224224
let string_of_channel ic =
225-
let n = 32768 in
226-
let s = Bytes.create n in
227-
let b = Buffer.create 1024 in
228-
let rec iter ic b s =
229-
let nread =
230-
try input ic s 0 n
231-
with End_of_file -> 0 in
232-
if nread > 0 then (
233-
Buffer.add_subbytes b s 0 nread;
234-
iter ic b s
235-
) in
236-
iter ic b s;
225+
let n = 4096 in
226+
let b = Buffer.create n in
227+
let rec iter ic b =
228+
match Buffer.add_channel b ic n with
229+
| () -> iter ic b
230+
| exception End_of_file -> ()
231+
in
232+
iter ic b;
237233
Buffer.contents b
238234

239235
let read file =

0 commit comments

Comments
 (0)