perf: optim in read_line

This commit is contained in:
Simon Cruanes 2024-04-04 22:39:12 -04:00
parent 9329c95ce7
commit 2292128d30
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4

View file

@ -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);