Skip to content

Commit

Permalink
perf: optim in read_line
Browse files Browse the repository at this point in the history
  • Loading branch information
c-cube committed Apr 5, 2024
1 parent 9329c95 commit 2292128
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/core/IO.ml
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,11 @@ module Input = struct
if Buf.size buf = 0 then raise End_of_file
);
let j = ref slice.off in
while !j < slice.off + slice.len && Bytes.get slice.bytes !j <> '\n' do
let limit = slice.off + slice.len in
while !j < limit && Bytes.get slice.bytes !j <> '\n' do
incr j
done;
if !j - slice.off < slice.len then (
if !j < limit then (
assert (Bytes.get slice.bytes !j = '\n');
(* line without '\n' *)
Buf.add_bytes buf slice.bytes slice.off (!j - slice.off);
Expand Down

0 comments on commit 2292128

Please sign in to comment.