diff --git a/master_changes.md b/master_changes.md index f0f9f93f92d..0dff999322b 100644 --- a/master_changes.md +++ b/master_changes.md @@ -168,3 +168,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] diff --git a/src/core/opamSystem.ml b/src/core/opamSystem.ml index 03c9c30487d..04a4e48e20c 100644 --- a/src/core/opamSystem.ml +++ b/src/core/opamSystem.ml @@ -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 =