-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
BufRead: Only flush the internal buffer if seeking outside of it. #46832
Conversation
Actually, don't merge this: there's an issue with the behaviour when seeking within a buffer and then reading past the end. @dtolnay to fix this, I'd need to store an extra "offset" field, and then when refilling the buffer, it will have to perform an extra seek to get back to the right position if the offset is non-zero. |
So I think I'm going to need some input on this: the original code has a comment explaining that There doesn't seem to be any justification for this guarantee, and it is not clear whether this should apply to @kballard it looks like you wrote the original implementation here - can you provide any input? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would have preferred a separate method specifically for seeking the underlying reader to self.pos, but at this point I believe we need to keep the guarantee about seek followed by into_inner. What are the trade-offs to consider?
To start with, all
Option 1 makes more sense to me, except that the original guarantee is not super useful if it only applies to |
Handing this off for a fresh set of eyes, but I think reasonable next steps would be:
|
@alexcrichton Do you remember why the original behavior was used? |
Dumping the buffer on every seek, and guaranteeing that |
Oh dear unfortunately I have no recollection of adding this beyond rubber-stamping it. I don't recall any particular discussion about this particular point. After trying to understand this for 20 minutes I also had to give up myself. I'm not familiar enough with everything at this point in time to give a recommendation myself. |
triage ping for you @sfackler! |
The @rust-lang/libs team discussed this PR during triage today and the conclusion was that we probably can't change the behavior here (as it's explicitly documented as not doing this), but would it be a possibility to perhaps add a new inherent method and mention it in the documentation? |
7119b6d
to
db78a33
Compare
db78a33
to
562ba04
Compare
@alexcrichton I've updated the PR accordingly. |
@bors: r+ |
📌 Commit c96f302 has been approved by |
☀️ Test successful - status-appveyor, status-travis |
Fixes #31100
r? @dtolnay