Skip to content
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

Optimize BufferedReader::read for large buffers. #18108

Merged
merged 1 commit into from
Oct 20, 2014
Merged

Optimize BufferedReader::read for large buffers. #18108

merged 1 commit into from
Oct 20, 2014

Conversation

mahkoh
Copy link
Contributor

@mahkoh mahkoh commented Oct 17, 2014

This optimizes read for the case in which the number of bytes
requested is larger than the internal buffer. Note that the first
comparison occurs again right afterwards and should thus be free. The
second comparison occurs only in the cold branch.

@mahkoh
Copy link
Contributor Author

mahkoh commented Oct 17, 2014

It might also be reasonable to use another bound such as buf.len() > self.cap/2 but I have not done any benchmarks.

@sfackler
Copy link
Member

Java makes the same optimization: http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/java/io/BufferedReader.java#195, though it calls fill afterwords, which seems kind of weird.

👍 here

@alexcrichton
Copy link
Member

Could you add a test for this as well? Just a smoke test ensuring that a gargantuan read bypasses the buffer. Other than that r=me

@mahkoh
Copy link
Contributor Author

mahkoh commented Oct 17, 2014

Updated.

This optimizes `read` for the case in which the number of bytes
requested is larger than the internal buffer. Note that the first
comparison occurs again right afterwards and should thus be free. The
second comparison occurs only in the cold branch.
@mahkoh
Copy link
Contributor Author

mahkoh commented Oct 19, 2014

Updated.

bors added a commit that referenced this pull request Oct 20, 2014
This optimizes `read` for the case in which the number of bytes
requested is larger than the internal buffer. Note that the first
comparison occurs again right afterwards and should thus be free. The
second comparison occurs only in the cold branch.
@bors bors closed this Oct 20, 2014
@bors bors merged commit 3839696 into rust-lang:master Oct 20, 2014
lnicola pushed a commit to lnicola/rust that referenced this pull request Sep 25, 2024
…kril

fix: Handle lint attributes that are under `#[cfg_attr]`

I forgot `cfg_attr` while working on rust-lang#18099. Although the original code also didn't handle that (although case lints specifically were correct, by virtue of using hir attrs).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants