Skip to content

Commit

Permalink
Speedup OpamSystem.read
Browse files Browse the repository at this point in the history
  • Loading branch information
kit-ty-kate committed Jul 24, 2024
1 parent cb2181b commit 69841b7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
1 change: 1 addition & 0 deletions master_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,4 @@ users)
* Add `OpamTypesBase.switch_selections_{compare,equal}`: proper comparison functions for `OpamTypes.switch_selections` [#6102 @kit-ty-kate]

## opam-core
* `OpamSystem.read`: Speedup by 8% [#5896 @kit-ty-kate]
20 changes: 8 additions & 12 deletions src/core/opamSystem.ml
Original file line number Diff line number Diff line change
Expand Up @@ -222,18 +222,14 @@ let remove_file file =
)

let string_of_channel ic =
let n = 32768 in
let s = Bytes.create n in
let b = Buffer.create 1024 in
let rec iter ic b s =
let nread =
try input ic s 0 n
with End_of_file -> 0 in
if nread > 0 then (
Buffer.add_subbytes b s 0 nread;
iter ic b s
) in
iter ic b s;
let n = 4096 in
let b = Buffer.create n in
let rec iter ic b =
match Buffer.add_channel b ic n with
| () -> iter ic b
| exception End_of_file -> ()
in
iter ic b;
Buffer.contents b

let read file =
Expand Down

0 comments on commit 69841b7

Please sign in to comment.