Skip to content

Commit fab9351

Browse files
committed
fix: do not refill buffer for an empty read
1 parent 2fd7de8 commit fab9351

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/core/in_buf.ml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,17 @@ class virtual t_from_refill ?(bytes = Bytes.create _default_buf_size) () =
1616
(** Consume [n] bytes from the inner buffer. *)
1717

1818
method input b i len : int =
19-
let buf = self#fill_buf () in
20-
21-
if buf.len > 0 then (
22-
let n = min len buf.len in
23-
Bytes.blit buf.bytes buf.off b i n;
24-
Slice.consume buf n;
25-
n
26-
) else
27-
0
19+
if len = 0 then 0
20+
else (
21+
let slice = self#fill_buf () in
22+
if slice.len > 0 then (
23+
let n = min len slice.len in
24+
Bytes.blit slice.bytes slice.off b i n;
25+
Slice.consume slice n;
26+
n
27+
) else
28+
0
29+
)
2830
(** Default implementation of [input] using [fill_buf] *)
2931
end
3032

0 commit comments

Comments
 (0)