Repository navigation
Conversation
the goal is to significantly accelerate `read_line` when this is available. A buf in \r handling in existing read_line is also fixed at the same time.
courtesy clod
0fd78db to
90f29cb
Compare
| as_buffered; | ||
| } | ||
|
|
||
| let create_in ~read ~input ~close : input = create_in_full ~read ~input ~close () |
There was a problem hiding this comment.
what is the point of having separate create_in_full? I can imagine backwards-compatibility in the strictest sense - signature mismatch for reimplementation of IO module - but new function breaks it same way
| ); | ||
| in_close = i.in_close | ||
| in_close = i.in_close; | ||
| as_buffered = (fun () -> None); |
There was a problem hiding this comment.
should this pass through buffer from i?
| | '\n' -> | ||
| () | ||
| | '\r' -> | ||
| if !cr then Buffer.add_char b '\r'; |
There was a problem hiding this comment.
this is a change in behaviour? it seems it fixes swallowing multiple \r at the end of line?
| - the view is shared with the owning {!input}: [read]/[input] on that | ||
| input and operations on the view consume from the same data. | ||
|
|
||
| Use {!create} rather than building the record by hand, as it |
There was a problem hiding this comment.
can use private to enforce this but i guess it is moot given the fields are mutable
| into [buf], sets [pos<-0], and [len<-num_of_bytes_refilled]. | ||
| When len>0 it may do nothing, or read more data. *) | ||
| } | ||
| (** View of {!input} with exposed buffer, only for some streams. Providing |
There was a problem hiding this comment.
i wondered if it is better to expose more functional api but then i realized stdlib still doesn't have substring type that we could mimic..
| while not !found && !i < last do | ||
| if Bytes.unsafe_get input.buf !i = c then found := true else incr i | ||
| done; | ||
| if !found then !i else -1 |
There was a problem hiding this comment.
String.find_from + compare with len?
| cr := ends_in_cr input len; | ||
| let s = Bytes.sub_string input.buf input.pos (skip_last_if_cr len) in | ||
| Buf_in.consume input (len+1); | ||
| s |
There was a problem hiding this comment.
fat chance i can review this with any confidence 😅
| if buf_in.len = 0 then raise No_more_input; | ||
| let c = Bytes.unsafe_get s buf_in.pos in | ||
| buf_in.pos <- buf_in.pos + 1; | ||
| buf_in.len <- buf_in.len - 1; |
This is related to performance work by alexander goryanets. My goal is to enable
read_lineto be actually fast for us, without giving up on theIO.inputabstraction.AI disclaimer: claude reviewed my code, and wrote tests. I wrote the src/ code.