New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add functions to replace BufReader's reader #122666
base: master
Are you sure you want to change the base?
Conversation
This allows the buffer of the BufRead to be used between multiple readers.
rustbot has assigned @Mark-Simulacrum. Use r? to explicitly pick a reviewer |
This
At which point you can just do |
That allocates a new buffer on the heap instead of reusing the allocation. |
Which likely isn't significant compared to the syscall overhead of opening the file. And I also find discarding the buffer and the old reader dubious since it can lead to data being dropped. This can be important for streams (e.g. TCP) where the data can only be obtained once. |
My specific use case is I have a few tens of thousand files that are a line based format that I'm parsing in a loop. I'd like my parser to not make the same allocation over and over when it could easily use the same buffer. I don't expect this to be useful on streams but it seemed useful here and was counter intuitive that I couldn't here. |
Do you have a benchmark suggesting this is a substantial win? |
We already allow replacing the underlying reader ( Discarding the buffer does not seem particularly useful to me for the known use case. Presumably, you want to exhaust the reader anyway, not accidentally drop contents. I would probably I think (a) is also not yet well-motivated, it feels like an even more rare use case. |
This allows the buffer of the BufRead to be used between multiple readers.