Skip to content

Commit 0585799

Browse files
committed
Speedup OpamSystem.read
1 parent 6beeb02 commit 0585799

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

src/core/opamSystem.ml

+12-14
Original file line numberDiff line numberDiff line change
@@ -216,20 +216,18 @@ let remove_file file =
216216
internal_error "Cannot remove %s (%s)." file (Printexc.to_string e)
217217
)
218218

219-
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;
232-
Buffer.contents b
219+
let string_of_channel =
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+
fun ic ->
228+
Buffer.clear b;
229+
iter ic b;
230+
Buffer.contents b
233231

234232
let read file =
235233
let ic =

0 commit comments

Comments
 (0)