From 2292128d305f108ffd0fd5bb4c5d5541b9f2c19b Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Thu, 4 Apr 2024 22:39:12 -0400 Subject: [PATCH] perf: optim in read_line --- src/core/IO.ml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/core/IO.ml b/src/core/IO.ml index 58771305..3307537a 100644 --- a/src/core/IO.ml +++ b/src/core/IO.ml @@ -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);