Closed MarinPostma closed 1 year ago
Thanks for your help. I would like to try dropping support for streaming / buf_redux and fix #23 and #21 (one can still use mmap if needed). Neither SQLite3 lexer nor lalrpop support streaming (but zero-copy). But don't close this PR because I am not sure how long that is going to take. Is it ok for you or you need a fix now ?
See https://github.com/gwenn/lemon-rs/pull/26/files#diff-3f786ccab1066df60ecf2d56744fa4fbc9b94efe78a12f66d0a5f986e81038baR100 (no unsafe / transmute anymore but no streaming anymore)
Fix an incorrect usage of unsafe.
The bug was that the
scan
method was using unsafe to return a reference to its internal buffer. This is incorrect, because the buffer can be overwritten, by either a call toconsume
orfill_buf
.This fix proposes to return owned slices in the form of
SmallVec
instead of references to the input. A default size of 16 bytes is chosen, which should prevent any allocation, most of the time.This allows the removal of the unsafe bit, and also simplifies the code, by removing lifetime bounds. The cost of this operation is a memcpy in most case, which is cheap.
There may be a solution that only works with references, but it would probably require significant changes.
fix #23