Skip to content

Add performance note for read_to_end and read_to_string #27213

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/libstd/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,8 @@ pub trait Read {
/// All bytes read from this source will be appended to the specified buffer
/// `buf`. This function will continuously call `read` to append more data to
/// `buf` until `read` returns either `Ok(0)` or an error of
/// non-`ErrorKind::Interrupted` kind.
/// non-`ErrorKind::Interrupted` kind. If the size of the input is known in
/// advance, performance will be improved by pre-reserving capacity in `buf`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a difference between reserving and pre-reserving? Both are things that happen in advance isn't it?

///
/// If successful, this function will return the total number of bytes read.
///
Expand Down Expand Up @@ -500,7 +501,8 @@ pub trait Read {
/// Read all bytes until EOF in this source, placing them into `buf`.
///
/// If successful, this function returns the number of bytes which were read
/// and appended to `buf`.
/// and appended to `buf`. If the size of the input is known in advance,
/// performance will be improved by pre-reserving capacity in `buf`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my comment above applies

///
/// # Errors
///
Expand Down